]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/textctrl.cpp
correct access for virtuals
[wxWidgets.git] / src / gtk / textctrl.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
8e13c1ec 2// Name: src/gtk/textctrl.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Id: $Id$
9fa72bd2 6// Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin, 2005 Mart Raudsepp
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/textctrl.h"
88a7a4e1
WS
14
15#ifndef WX_PRECOMP
16 #include "wx/intl.h"
e4db172a 17 #include "wx/log.h"
de6185e2 18 #include "wx/utils.h"
8e609c82 19 #include "wx/panel.h"
88a7a4e1
WS
20#endif
21
c77a6796 22#include "wx/math.h"
ae0bdb01 23#include "wx/settings.h"
fab591c5 24#include "wx/strconv.h"
cc3da3f8 25#include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
c801d85f 26
a81258be
RR
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <ctype.h>
463c4d71 30#include "wx/math.h"
a81258be 31
9e691f46
VZ
32#include "wx/gtk/private.h"
33#include <gdk/gdkkeysyms.h>
b292e2f5
RR
34
35//-----------------------------------------------------------------------------
36// data
37//-----------------------------------------------------------------------------
38
65045edd 39extern wxCursor g_globalCursor;
d7fa7eaa 40extern wxWindowGTK *g_delayedFocus;
b292e2f5 41
eda40bfc
VZ
42// ----------------------------------------------------------------------------
43// helpers
44// ----------------------------------------------------------------------------
45
418cf02e
JS
46extern "C" {
47static void wxGtkOnRemoveTag(GtkTextBuffer *buffer,
48 GtkTextTag *tag,
49 GtkTextIter *start,
50 GtkTextIter *end,
50aee613 51 char *prefix)
418cf02e
JS
52{
53 gchar *name;
54 g_object_get (tag, "name", &name, NULL);
55
50aee613
MR
56 if (!name || strncmp(name, prefix, strlen(prefix)))
57 // anonymous tag or not starting with prefix - don't remove
9fa72bd2 58 g_signal_stop_emission_by_name (buffer, "remove_tag");
418cf02e
JS
59
60 g_free(name);
61}
62}
63
64extern "C" {
25497324
KH
65static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer *text_buffer,
66 const wxTextAttr& attr,
67 GtkTextIter *start,
68 GtkTextIter *end)
69{
70 static gchar buf[1024];
71 GtkTextTag *tag;
72
9fa72bd2
MR
73 gulong remove_handler_id = g_signal_connect (text_buffer, "remove_tag",
74 G_CALLBACK (wxGtkOnRemoveTag), gpointer("WX"));
418cf02e 75 gtk_text_buffer_remove_all_tags(text_buffer, start, end);
9fa72bd2 76 g_signal_handler_disconnect (text_buffer, remove_handler_id);
418cf02e 77
25497324
KH
78 if (attr.HasFont())
79 {
80 char *font_string;
81 PangoFontDescription *font_description = attr.GetFont().GetNativeFontInfo()->description;
82 font_string = pango_font_description_to_string(font_description);
83 g_snprintf(buf, sizeof(buf), "WXFONT %s", font_string);
84 tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
85 buf );
86 if (!tag)
87 tag = gtk_text_buffer_create_tag( text_buffer, buf,
88 "font-desc", font_description,
89 NULL );
90 gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
91 g_free (font_string);
18634476
VZ
92
93 if (attr.GetFont().GetUnderlined())
94 {
95 g_snprintf(buf, sizeof(buf), "WXFONTUNDERLINE");
96 tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
97 buf );
98 if (!tag)
99 tag = gtk_text_buffer_create_tag( text_buffer, buf,
100 "underline-set", TRUE,
101 "underline", PANGO_UNDERLINE_SINGLE,
102 NULL );
103 gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
104 }
25497324
KH
105 }
106
107 if (attr.HasTextColour())
108 {
109 GdkColor *colFg = attr.GetTextColour().GetColor();
110 g_snprintf(buf, sizeof(buf), "WXFORECOLOR %d %d %d",
111 colFg->red, colFg->green, colFg->blue);
112 tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
113 buf );
114 if (!tag)
115 tag = gtk_text_buffer_create_tag( text_buffer, buf,
116 "foreground-gdk", colFg, NULL );
117 gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
118 }
119
120 if (attr.HasBackgroundColour())
121 {
122 GdkColor *colBg = attr.GetBackgroundColour().GetColor();
123 g_snprintf(buf, sizeof(buf), "WXBACKCOLOR %d %d %d",
124 colBg->red, colBg->green, colBg->blue);
125 tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
126 buf );
127 if (!tag)
128 tag = gtk_text_buffer_create_tag( text_buffer, buf,
129 "background-gdk", colBg, NULL );
130 gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
131 }
50aee613
MR
132
133 if (attr.HasAlignment())
134 {
135 GtkTextIter para_start, para_end = *end;
136 gtk_text_buffer_get_iter_at_line( text_buffer,
137 &para_start,
138 gtk_text_iter_get_line(start) );
139 gtk_text_iter_forward_line(&para_end);
140
9fa72bd2 141 remove_handler_id = g_signal_connect (text_buffer, "remove_tag",
50aee613
MR
142 G_CALLBACK(wxGtkOnRemoveTag),
143 gpointer("WXALIGNMENT"));
144 gtk_text_buffer_remove_all_tags( text_buffer, &para_start, &para_end );
9fa72bd2 145 g_signal_handler_disconnect (text_buffer, remove_handler_id);
50aee613
MR
146
147 GtkJustification align;
148 switch (attr.GetAlignment())
149 {
150 default:
151 align = GTK_JUSTIFY_LEFT;
152 break;
153 case wxTEXT_ALIGNMENT_RIGHT:
154 align = GTK_JUSTIFY_RIGHT;
155 break;
156 case wxTEXT_ALIGNMENT_CENTER:
157 align = GTK_JUSTIFY_CENTER;
158 break;
159 // gtk+ doesn't support justify as of gtk+-2.7.4
160 }
161
162 g_snprintf(buf, sizeof(buf), "WXALIGNMENT %d", align);
163 tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
164 buf );
165 if (!tag)
166 tag = gtk_text_buffer_create_tag( text_buffer, buf,
167 "justification", align, NULL );
168 gtk_text_buffer_apply_tag( text_buffer, tag, &para_start, &para_end );
169 }
25497324 170}
418cf02e 171}
25497324 172
418cf02e 173extern "C" {
cc3da3f8
RR
174static void wxGtkTextInsert(GtkWidget *text,
175 GtkTextBuffer *text_buffer,
176 const wxTextAttr& attr,
fbfb8bcc 177 const wxCharBuffer& buffer)
cc3da3f8
RR
178
179{
25497324
KH
180 gint start_offset;
181 GtkTextIter iter, start;
cc3da3f8 182
a61bbf87
JS
183 gtk_text_buffer_get_iter_at_mark( text_buffer, &iter,
184 gtk_text_buffer_get_insert (text_buffer) );
25497324
KH
185 start_offset = gtk_text_iter_get_offset (&iter);
186 gtk_text_buffer_insert( text_buffer, &iter, buffer, strlen(buffer) );
187
188 gtk_text_buffer_get_iter_at_offset (text_buffer, &start, start_offset);
a61bbf87 189
25497324 190 wxGtkTextApplyTagsFromAttr(text_buffer, attr, &start, &iter);
cc3da3f8 191}
418cf02e 192}
eda40bfc 193
ce2f50e3
VZ
194// ----------------------------------------------------------------------------
195// "insert_text" for GtkEntry
196// ----------------------------------------------------------------------------
197
865bb325 198extern "C" {
ce2f50e3
VZ
199static void
200gtk_insert_text_callback(GtkEditable *editable,
201 const gchar *new_text,
202 gint new_text_length,
203 gint *position,
204 wxTextCtrl *win)
205{
76fcf0f2
RR
206 if (g_isIdle)
207 wxapp_install_idle_handler();
208
ce2f50e3
VZ
209 // we should only be called if we have a max len limit at all
210 GtkEntry *entry = GTK_ENTRY (editable);
211
212 wxCHECK_RET( entry->text_max_length, _T("shouldn't be called") );
213
214 // check that we don't overflow the max length limit
215 //
216 // FIXME: this doesn't work when we paste a string which is going to be
217 // truncated
218 if ( entry->text_length == entry->text_max_length )
219 {
220 // we don't need to run the base class version at all
9fa72bd2 221 g_signal_stop_emission_by_name (editable, "insert_text");
ce2f50e3
VZ
222
223 // remember that the next changed signal is to be ignored to avoid
224 // generating a dummy wxEVT_COMMAND_TEXT_UPDATED event
225 win->IgnoreNextTextUpdate();
226
227 // and generate the correct one ourselves
228 wxCommandEvent event(wxEVT_COMMAND_TEXT_MAXLEN, win->GetId());
229 event.SetEventObject(win);
230 event.SetString(win->GetValue());
231 win->GetEventHandler()->ProcessEvent( event );
232 }
233}
865bb325 234}
ce2f50e3 235
9440c3d0
KH
236// Implementation of wxTE_AUTO_URL for wxGTK2 by Mart Raudsepp,
237
865bb325 238extern "C" {
9440c3d0
KH
239static void
240au_apply_tag_callback(GtkTextBuffer *buffer,
241 GtkTextTag *tag,
242 GtkTextIter *start,
243 GtkTextIter *end,
244 gpointer textctrl)
245{
246 if(tag == gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), "wxUrl"))
9fa72bd2 247 g_signal_stop_emission_by_name (buffer, "apply_tag");
9440c3d0 248}
865bb325 249}
9440c3d0
KH
250
251//-----------------------------------------------------------------------------
252// GtkTextCharPredicates for gtk_text_iter_*_find_char
253//-----------------------------------------------------------------------------
254
865bb325 255extern "C" {
9440c3d0
KH
256static gboolean
257pred_whitespace (gunichar ch, gpointer user_data)
258{
259 return g_unichar_isspace(ch);
260}
865bb325 261}
9440c3d0 262
865bb325 263extern "C" {
9440c3d0
KH
264static gboolean
265pred_non_whitespace (gunichar ch, gpointer user_data)
266{
267 return !g_unichar_isspace(ch);
268}
865bb325 269}
9440c3d0 270
865bb325 271extern "C" {
9440c3d0
KH
272static gboolean
273pred_nonpunct (gunichar ch, gpointer user_data)
274{
275 return !g_unichar_ispunct(ch);
276}
865bb325 277}
9440c3d0 278
865bb325 279extern "C" {
9440c3d0
KH
280static gboolean
281pred_nonpunct_or_slash (gunichar ch, gpointer user_data)
282{
283 return !g_unichar_ispunct(ch) || ch == '/';
284}
865bb325 285}
9440c3d0
KH
286
287//-----------------------------------------------------------------------------
288// Check for links between s and e and correct tags as necessary
289//-----------------------------------------------------------------------------
290
291// This function should be made match better while being efficient at one point.
292// Most probably with a row of regular expressions.
865bb325 293extern "C" {
9440c3d0
KH
294static void
295au_check_word( GtkTextIter *s, GtkTextIter *e )
296{
297 static const char *URIPrefixes[] =
298 {
299 "http://",
300 "ftp://",
301 "www.",
302 "ftp.",
303 "mailto://",
304 "https://",
305 "file://",
306 "nntp://",
307 "news://",
308 "telnet://",
309 "mms://",
310 "gopher://",
311 "prospero://",
312 "wais://",
313 };
314
315 GtkTextIter start = *s, end = *e;
316 GtkTextBuffer *buffer = gtk_text_iter_get_buffer(s);
418cf02e 317
9440c3d0
KH
318 // Get our special link tag
319 GtkTextTag *tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), "wxUrl");
320
321 // Get rid of punctuation from beginning and end.
322 // Might want to move this to au_check_range if an improved link checking doesn't
323 // use some intelligent punctuation checking itself (beware of undesired iter modifications).
324 if(g_unichar_ispunct( gtk_text_iter_get_char( &start ) ) )
325 gtk_text_iter_forward_find_char( &start, pred_nonpunct, NULL, e );
326
327 gtk_text_iter_backward_find_char( &end, pred_nonpunct_or_slash, NULL, &start );
328 gtk_text_iter_forward_char(&end);
329
330 gchar* text = gtk_text_iter_get_text( &start, &end );
331 size_t len = strlen(text), prefix_len;
332 size_t n;
333
334 for( n = 0; n < WXSIZEOF(URIPrefixes); ++n )
335 {
336 prefix_len = strlen(URIPrefixes[n]);
337 if((len > prefix_len) && !strncasecmp(text, URIPrefixes[n], prefix_len))
338 break;
339 }
340
341 if(n < WXSIZEOF(URIPrefixes))
342 {
9fa72bd2
MR
343 gulong signal_id = g_signal_handler_find (buffer,
344 (GSignalMatchType) (G_SIGNAL_MATCH_FUNC),
345 0, 0, NULL,
346 (gpointer)au_apply_tag_callback, NULL);
9440c3d0 347
9fa72bd2 348 g_signal_handler_block (buffer, signal_id);
9440c3d0 349 gtk_text_buffer_apply_tag(buffer, tag, &start, &end);
9fa72bd2 350 g_signal_handler_unblock (buffer, signal_id);
9440c3d0
KH
351 }
352}
865bb325 353}
9440c3d0 354
865bb325 355extern "C" {
9440c3d0
KH
356static void
357au_check_range(GtkTextIter *s,
358 GtkTextIter *range_end)
359{
360 GtkTextIter range_start = *s;
361 GtkTextIter word_end;
362 GtkTextBuffer *buffer = gtk_text_iter_get_buffer(s);
363 GtkTextTag *tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer), "wxUrl");
364
365 gtk_text_buffer_remove_tag(buffer, tag, s, range_end);
366
367 if(g_unichar_isspace(gtk_text_iter_get_char(&range_start)))
368 gtk_text_iter_forward_find_char(&range_start, pred_non_whitespace, NULL, range_end);
369
370 while(!gtk_text_iter_equal(&range_start, range_end))
371 {
372 word_end = range_start;
373 gtk_text_iter_forward_find_char(&word_end, pred_whitespace, NULL, range_end);
374
375 // Now we should have a word delimited by range_start and word_end, correct link tags
376 au_check_word(&range_start, &word_end);
377
378 range_start = word_end;
379 gtk_text_iter_forward_find_char(&range_start, pred_non_whitespace, NULL, range_end);
380 }
381}
865bb325 382}
9440c3d0
KH
383
384//-----------------------------------------------------------------------------
385// "insert-text" for GtkTextBuffer
386//-----------------------------------------------------------------------------
387
865bb325 388extern "C" {
9440c3d0
KH
389static void
390au_insert_text_callback(GtkTextBuffer *buffer,
391 GtkTextIter *end,
392 gchar *text,
393 gint len,
394 wxTextCtrl *win)
395{
396 if (!len || !(win->GetWindowStyleFlag() & wxTE_AUTO_URL) )
397 return;
398
399 GtkTextIter start = *end;
400 gtk_text_iter_backward_chars(&start, g_utf8_strlen(text, len));
401
402 GtkTextIter line_start = start;
403 GtkTextIter line_end = *end;
404 GtkTextIter words_start = start;
405 GtkTextIter words_end = *end;
406
407 gtk_text_iter_set_line(&line_start, gtk_text_iter_get_line(&start));
408 gtk_text_iter_forward_to_line_end(&line_end);
409 gtk_text_iter_backward_find_char(&words_start, pred_whitespace, NULL, &line_start);
410 gtk_text_iter_forward_find_char(&words_end, pred_whitespace, NULL, &line_end);
411
412 au_check_range(&words_start, &words_end);
413}
865bb325 414}
9440c3d0
KH
415
416//-----------------------------------------------------------------------------
417// "delete-range" for GtkTextBuffer
418//-----------------------------------------------------------------------------
419
865bb325 420extern "C" {
9440c3d0
KH
421static void
422au_delete_range_callback(GtkTextBuffer *buffer,
423 GtkTextIter *start,
424 GtkTextIter *end,
425 wxTextCtrl *win)
426{
427 if( !(win->GetWindowStyleFlag() & wxTE_AUTO_URL) )
428 return;
429
430 GtkTextIter line_start = *start, line_end = *end;
431
432 gtk_text_iter_set_line(&line_start, gtk_text_iter_get_line(start));
433 gtk_text_iter_forward_to_line_end(&line_end);
434 gtk_text_iter_backward_find_char(start, pred_whitespace, NULL, &line_start);
435 gtk_text_iter_forward_find_char(end, pred_whitespace, NULL, &line_end);
436
437 au_check_range(start, end);
438}
865bb325 439}
9440c3d0
KH
440
441
c801d85f 442//-----------------------------------------------------------------------------
2f2aa628 443// "changed"
c801d85f
KB
444//-----------------------------------------------------------------------------
445
865bb325 446extern "C" {
805dd538 447static void
ba3f6b44 448gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win )
484e45bf 449{
ce2f50e3
VZ
450 if ( win->IgnoreTextUpdate() )
451 return;
452
a2053b27 453 if (!win->m_hasVMT) return;
805dd538 454
bb69661b 455 if (g_isIdle)
3c679789 456 wxapp_install_idle_handler();
a8bf1826 457
034be888 458 win->SetModified();
a8bf1826 459
f03fc89f 460 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
2830bf19
RR
461 event.SetEventObject( win );
462 win->GetEventHandler()->ProcessEvent( event );
6de97a3b 463}
865bb325 464}
112892b9 465
41b81aed
RR
466//-----------------------------------------------------------------------------
467// "expose_event" from scrolled window and textview
468//-----------------------------------------------------------------------------
469
865bb325 470extern "C" {
41b81aed
RR
471static gboolean
472gtk_text_exposed_callback( GtkWidget *widget, GdkEventExpose *event, wxTextCtrl *win )
473{
474 return TRUE;
475}
865bb325 476}
1c35b54e 477
1c35b54e 478
2f2aa628
RR
479//-----------------------------------------------------------------------------
480// wxTextCtrl
481//-----------------------------------------------------------------------------
482
483IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl)
484
c801d85f 485BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
2830bf19 486 EVT_CHAR(wxTextCtrl::OnChar)
e702ff0f
JS
487
488 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
489 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
490 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
491 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
492 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
493
494 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
495 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
496 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
497 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
498 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
9440c3d0 499
9440c3d0
KH
500 // wxTE_AUTO_URL wxTextUrl support. Currently only creates
501 // wxTextUrlEvent in the same cases as wxMSW, more can be added here.
502 EVT_MOTION (wxTextCtrl::OnUrlMouseEvent)
503 EVT_LEFT_DOWN (wxTextCtrl::OnUrlMouseEvent)
504 EVT_LEFT_UP (wxTextCtrl::OnUrlMouseEvent)
505 EVT_LEFT_DCLICK (wxTextCtrl::OnUrlMouseEvent)
506 EVT_RIGHT_DOWN (wxTextCtrl::OnUrlMouseEvent)
507 EVT_RIGHT_UP (wxTextCtrl::OnUrlMouseEvent)
508 EVT_RIGHT_DCLICK(wxTextCtrl::OnUrlMouseEvent)
c801d85f
KB
509END_EVENT_TABLE()
510
01041145 511void wxTextCtrl::Init()
f5abe911 512{
ce2f50e3 513 m_ignoreNextUpdate =
7d8268a1
WS
514 m_modified = false;
515 SetUpdateFont(false);
85396430 516 m_text = NULL;
41b81aed 517 m_frozenness = 0;
9440c3d0
KH
518 m_gdkHandCursor = NULL;
519 m_gdkXTermCursor = NULL;
9440c3d0
KH
520}
521
522wxTextCtrl::~wxTextCtrl()
523{
9440c3d0
KH
524 if(m_gdkHandCursor)
525 gdk_cursor_unref(m_gdkHandCursor);
526 if(m_gdkXTermCursor)
527 gdk_cursor_unref(m_gdkXTermCursor);
f5abe911 528}
13289f04 529
13111b2a
VZ
530wxTextCtrl::wxTextCtrl( wxWindow *parent,
531 wxWindowID id,
532 const wxString &value,
533 const wxPoint &pos,
534 const wxSize &size,
535 long style,
536 const wxValidator& validator,
537 const wxString &name )
f5abe911 538{
01041145
VZ
539 Init();
540
f5abe911
RR
541 Create( parent, id, value, pos, size, style, validator, name );
542}
c801d85f 543
13111b2a
VZ
544bool wxTextCtrl::Create( wxWindow *parent,
545 wxWindowID id,
546 const wxString &value,
547 const wxPoint &pos,
548 const wxSize &size,
549 long style,
550 const wxValidator& validator,
551 const wxString &name )
c801d85f 552{
7d8268a1
WS
553 m_needParent = true;
554 m_acceptsFocus = true;
484e45bf 555
4dcaf11a
RR
556 if (!PreCreation( parent, pos, size ) ||
557 !CreateBase( parent, id, pos, size, style, validator, name ))
558 {
223d09f6 559 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
7d8268a1 560 return false;
4dcaf11a 561 }
6de97a3b 562
2830bf19 563 bool multi_line = (style & wxTE_MULTILINE) != 0;
a8bf1826 564
ab46dc18 565 if (multi_line)
2830bf19 566 {
fab591c5
RR
567 // Create view
568 m_text = gtk_text_view_new();
a8bf1826 569
41b81aed 570 m_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
a8bf1826 571
fab591c5
RR
572 // create scrolled window
573 m_widget = gtk_scrolled_window_new( NULL, NULL );
574 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget ),
575 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
a8bf1826 576
fab591c5
RR
577 // Insert view into scrolled window
578 gtk_container_add( GTK_CONTAINER(m_widget), m_text );
a8bf1826 579
c2110823 580 // translate wx wrapping style to GTK+
9ddb3948 581 GtkWrapMode wrap;
c2110823 582 if ( HasFlag( wxTE_DONTWRAP ) )
9ddb3948 583 wrap = GTK_WRAP_NONE;
c4590236 584 else if ( HasFlag( wxTE_CHARWRAP ) )
9ddb3948 585 wrap = GTK_WRAP_CHAR;
c4590236 586 else if ( HasFlag( wxTE_WORDWRAP ) )
9ddb3948 587 wrap = GTK_WRAP_WORD;
c4590236
VZ
588 else // HasFlag(wxTE_BESTWRAP) always true as wxTE_BESTWRAP == 0
589 {
590 // GTK_WRAP_WORD_CHAR seems to be new in GTK+ 2.4
591#ifdef __WXGTK24__
c79146df
VZ
592 if ( !gtk_check_version(2,4,0) )
593 {
594 wrap = GTK_WRAP_WORD_CHAR;
595 }
596 else
c4590236 597#endif
34b8f3ef 598 wrap = GTK_WRAP_WORD;
c4590236 599 }
9ddb3948
VZ
600
601 gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), wrap );
805dd538 602
6493aaca 603 GtkScrolledWindowSetBorder(m_widget, style);
7d8268a1 604
e327fddf
KH
605 gtk_widget_add_events( GTK_WIDGET(m_text), GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK );
606
055e633d 607 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
2830bf19
RR
608 }
609 else
610 {
fab591c5 611 // a single-line text control: no need for scrollbars
2830bf19 612 m_widget =
1c35b54e 613 m_text = gtk_entry_new();
44c5573d 614
02a6e358
RR
615 if (style & wxNO_BORDER)
616 g_object_set( GTK_ENTRY(m_text), "has-frame", FALSE, NULL );
2830bf19 617 }
484e45bf 618
db434467 619 m_parent->DoAddChild( this );
eda40bfc 620
76fcf0f2 621 m_focusWidget = m_text;
db434467 622
abdeb9e7 623 PostCreation(size);
484e45bf 624
2830bf19 625 if (multi_line)
0c131a5a 626 {
2830bf19 627 gtk_widget_show(m_text);
0c131a5a
VZ
628 SetVScrollAdjustment(gtk_scrolled_window_get_vadjustment((GtkScrolledWindow*)m_widget));
629 }
13289f04 630
7d8268a1 631 if (!value.empty())
2830bf19 632 {
fab591c5 633 SetValue( value );
2830bf19 634 }
484e45bf 635
2830bf19
RR
636 if (style & wxTE_PASSWORD)
637 {
638 if (!multi_line)
639 gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE );
640 }
8bbe427f 641
2830bf19
RR
642 if (style & wxTE_READONLY)
643 {
644 if (!multi_line)
6f85e712 645 gtk_editable_set_editable( GTK_EDITABLE(m_text), FALSE );
fab591c5 646 else
98a8daf4 647 gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text), FALSE);
98a8daf4
VS
648 }
649
c663fbea
VS
650 if (multi_line)
651 {
652 if (style & wxTE_RIGHT)
653 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text), GTK_JUSTIFY_RIGHT );
654 else if (style & wxTE_CENTRE)
655 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text), GTK_JUSTIFY_CENTER );
656 // Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
657 }
c663fbea
VS
658 else
659 {
77f70672
RR
660#ifdef __WXGTK24__
661 // gtk_entry_set_alignment was introduced in gtk+-2.3.5
662 if (!gtk_check_version(2,4,0))
663 {
664 if (style & wxTE_RIGHT)
665 gtk_entry_set_alignment( GTK_ENTRY(m_text), 1.0 );
666 else if (style & wxTE_CENTRE)
667 gtk_entry_set_alignment( GTK_ENTRY(m_text), 0.5 );
668 }
669#endif
c663fbea 670 }
7d8268a1 671
fab591c5 672 // We want to be notified about text changes.
fab591c5
RR
673 if (multi_line)
674 {
9fa72bd2
MR
675 g_signal_connect (m_buffer, "changed",
676 G_CALLBACK (gtk_text_changed_callback), this);
9440c3d0
KH
677
678 // .. and handle URLs on multi-line controls with wxTE_AUTO_URL style
679 if (style & wxTE_AUTO_URL)
680 {
681 GtkTextIter start, end;
682 m_gdkHandCursor = gdk_cursor_new(GDK_HAND2);
683 m_gdkXTermCursor = gdk_cursor_new(GDK_XTERM);
684
685 // We create our wxUrl tag here for slight efficiency gain - we
686 // don't have to check for the tag existance in callbacks,
687 // hereby it's guaranteed to exist.
688 gtk_text_buffer_create_tag(m_buffer, "wxUrl",
689 "foreground", "blue",
690 "underline", PANGO_UNDERLINE_SINGLE,
691 NULL);
692
693 // Check for URLs after each text change
9fa72bd2
MR
694 g_signal_connect_after (m_buffer, "insert_text",
695 G_CALLBACK (au_insert_text_callback), this);
696 g_signal_connect_after (m_buffer, "delete_range",
697 G_CALLBACK (au_delete_range_callback), this);
9440c3d0
KH
698
699 // Block all wxUrl tag applying unless we do it ourselves, in which case we
700 // block this callback temporarily. This takes care of gtk+ internal
701 // gtk_text_buffer_insert_range* calls that would copy our URL tag otherwise,
702 // which is undesired because only a part of the URL might be copied.
703 // The insert-text signal emitted inside it will take care of newly formed
704 // or wholly copied URLs.
9fa72bd2
MR
705 g_signal_connect (m_buffer, "apply_tag",
706 G_CALLBACK (au_apply_tag_callback), NULL);
9440c3d0
KH
707
708 // Check for URLs in the initial string passed to Create
709 gtk_text_buffer_get_start_iter(m_buffer, &start);
710 gtk_text_buffer_get_end_iter(m_buffer, &end);
711 au_check_range(&start, &end);
712 }
fab591c5
RR
713 }
714 else
fab591c5 715 {
9fa72bd2
MR
716 g_signal_connect (m_text, "changed",
717 G_CALLBACK (gtk_text_changed_callback), this);
fab591c5 718 }
ce16e5d7 719
65045edd 720 m_cursor = wxCursor( wxCURSOR_IBEAM );
13111b2a 721
9d522606 722 wxTextAttr attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont());
17665a2b
VZ
723 SetDefaultStyle( attrDef );
724
7d8268a1 725 return true;
2830bf19 726}
484e45bf 727
9d522606 728
2830bf19
RR
729void wxTextCtrl::CalculateScrollbar()
730{
6de97a3b 731}
c801d85f 732
03f38c58 733wxString wxTextCtrl::GetValue() const
c801d85f 734{
902725ee 735 wxCHECK_MSG( m_text != NULL, wxEmptyString, wxT("invalid text ctrl") );
8bbe427f 736
2830bf19
RR
737 wxString tmp;
738 if (m_windowStyle & wxTE_MULTILINE)
739 {
fab591c5 740 GtkTextIter start;
41b81aed 741 gtk_text_buffer_get_start_iter( m_buffer, &start );
fab591c5 742 GtkTextIter end;
41b81aed
RR
743 gtk_text_buffer_get_end_iter( m_buffer, &end );
744 gchar *text = gtk_text_buffer_get_text( m_buffer, &start, &end, TRUE );
5b87f8bf 745
a3669332
VZ
746 const wxWxCharBuffer buf = wxGTK_CONV_BACK(text);
747 if ( buf )
748 tmp = buf;
a8bf1826 749
fab591c5 750 g_free( text );
2830bf19
RR
751 }
752 else
753 {
a3669332
VZ
754 const gchar *text = gtk_entry_get_text( GTK_ENTRY(m_text) );
755 const wxWxCharBuffer buf = wxGTK_CONV_BACK( text );
756 if ( buf )
757 tmp = buf;
2830bf19 758 }
a8bf1826 759
2830bf19 760 return tmp;
6de97a3b 761}
c801d85f
KB
762
763void wxTextCtrl::SetValue( const wxString &value )
764{
223d09f6 765 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 766
2830bf19
RR
767 if (m_windowStyle & wxTE_MULTILINE)
768 {
a3669332 769 const wxCharBuffer buffer(wxGTK_CONV(value));
430ae62e
JS
770 if ( !buffer )
771 {
772 // what else can we do? at least don't crash...
773 return;
774 }
418cf02e 775
a3669332
VZ
776 if (gtk_text_buffer_get_char_count(m_buffer) != 0)
777 IgnoreNextTextUpdate();
778
41b81aed 779 gtk_text_buffer_set_text( m_buffer, buffer, strlen(buffer) );
2830bf19 780 }
265c34ee 781 else // single line
2830bf19 782 {
265c34ee
VZ
783 // gtk_entry_set_text() emits two "changed" signals because internally
784 // it calls gtk_editable_delete_text() and gtk_editable_insert_text()
785 // but we want to have only one event
786 IgnoreNextTextUpdate();
787
788 gtk_entry_set_text( GTK_ENTRY(m_text), wxGTK_CONV(value) );
2830bf19 789 }
f6bcfd97
BP
790
791 // GRG, Jun/2000: Changed this after a lot of discussion in
77ffb593 792 // the lists. wxWidgets 2.2 will have a set of flags to
f6bcfd97
BP
793 // customize this behaviour.
794 SetInsertionPoint(0);
a8bf1826 795
7d8268a1 796 m_modified = false;
6de97a3b 797}
c801d85f
KB
798
799void wxTextCtrl::WriteText( const wxString &text )
800{
223d09f6 801 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 802
17665a2b
VZ
803 if ( text.empty() )
804 return;
484e45bf 805
a3669332
VZ
806 const wxCharBuffer buffer(wxGTK_CONV(text));
807 if ( !buffer )
808 {
809 // what else can we do? at least don't crash...
810 return;
811 }
812
c04ec496
VZ
813 // gtk_text_changed_callback() will set m_modified to true but m_modified
814 // shouldn't be changed by the program writing to the text control itself,
815 // so save the old value and restore when we're done
816 bool oldModified = m_modified;
817
17665a2b 818 if ( m_windowStyle & wxTE_MULTILINE )
2830bf19 819 {
ea5449ae
RD
820 // First remove the selection if there is one
821 // TODO: Is there an easier GTK specific way to do this?
822 long from, to;
823 GetSelection(&from, &to);
824 if (from != to)
825 Remove(from, to);
826
827 // Insert the text
41b81aed 828 wxGtkTextInsert( m_text, m_buffer, m_defaultStyle, buffer );
a8bf1826 829
71aba833
VZ
830 GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(m_widget) );
831 // Scroll to cursor, but only if scrollbar thumb is at the very bottom
c77a6796 832 if ( wxIsSameDouble(adj->value, adj->upper - adj->page_size) )
71aba833
VZ
833 {
834 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text),
41b81aed 835 gtk_text_buffer_get_insert( m_buffer ), 0.0, FALSE, 0.0, 1.0 );
71aba833 836 }
2830bf19 837 }
17665a2b 838 else // single line
2830bf19 839 {
2b5f62a0
VZ
840 // First remove the selection if there is one
841 gtk_editable_delete_selection( GTK_EDITABLE(m_text) );
842
ba3f6b44 843 // This moves the cursor pos to behind the inserted text.
afa7bd1e 844 gint len = gtk_editable_get_position(GTK_EDITABLE(m_text));
a8bf1826 845
fab591c5 846 gtk_editable_insert_text( GTK_EDITABLE(m_text), buffer, strlen(buffer), &len );
a8bf1826 847
ba3f6b44 848 // Bring entry's cursor uptodate.
6f85e712 849 gtk_editable_set_position( GTK_EDITABLE(m_text), len );
2830bf19 850 }
eda40bfc 851
c04ec496 852 m_modified = oldModified;
6de97a3b 853}
c801d85f 854
a6e21573
HH
855void wxTextCtrl::AppendText( const wxString &text )
856{
ba3f6b44
RR
857 SetInsertionPointEnd();
858 WriteText( text );
859}
2df7be7f 860
ba3f6b44
RR
861wxString wxTextCtrl::GetLineText( long lineNo ) const
862{
a6e21573
HH
863 if (m_windowStyle & wxTE_MULTILINE)
864 {
905f2110 865 GtkTextIter line;
41b81aed 866 gtk_text_buffer_get_iter_at_line(m_buffer,&line,lineNo);
8c6785f0
MR
867 GtkTextIter end = line;
868 gtk_text_iter_forward_to_line_end(&end);
41b81aed 869 gchar *text = gtk_text_buffer_get_text(m_buffer,&line,&end,TRUE);
58192970 870 wxString result(wxGTK_CONV_BACK(text));
905f2110 871 g_free(text);
8c6785f0 872 return result;
a6e21573 873 }
ba3f6b44 874 else
a81258be 875 {
ba3f6b44
RR
876 if (lineNo == 0) return GetValue();
877 return wxEmptyString;
a81258be 878 }
6de97a3b 879}
c801d85f 880
a81258be
RR
881void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
882{
ac0d36b5
HH
883 /* If you implement this, don't forget to update the documentation!
884 * (file docs/latex/wx/text.tex) */
223d09f6 885 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
a81258be 886}
112892b9 887
0efe5ba7 888bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
c801d85f 889{
96385642 890 if ( m_windowStyle & wxTE_MULTILINE )
805dd538 891 {
f29a481a
MR
892 GtkTextIter iter;
893 gtk_text_buffer_get_iter_at_offset(m_buffer, &iter, pos);
894 if (gtk_text_iter_is_end(&iter))
895 return false;
896
897 *y = gtk_text_iter_get_line(&iter);
898 *x = gtk_text_iter_get_line_offset(&iter);
805dd538 899 }
96385642
VZ
900 else // single line control
901 {
2829d9e3 902 if ( pos <= GTK_ENTRY(m_text)->text_length )
96385642 903 {
ac0d36b5 904 *y = 0;
96385642
VZ
905 *x = pos;
906 }
907 else
908 {
909 // index out of bounds
7d8268a1 910 return false;
96385642 911 }
8bbe427f 912 }
96385642 913
7d8268a1 914 return true;
6de97a3b 915}
c801d85f 916
e3ca08dd 917long wxTextCtrl::XYToPosition(long x, long y ) const
c801d85f 918{
2830bf19 919 if (!(m_windowStyle & wxTE_MULTILINE)) return 0;
805dd538 920
f29a481a 921 GtkTextIter iter;
21d23b88
MR
922 if (y >= gtk_text_buffer_get_line_count (m_buffer))
923 return -1;
924
925 gtk_text_buffer_get_iter_at_line(m_buffer, &iter, y);
926 if (x >= gtk_text_iter_get_chars_in_line (&iter))
927 return -1;
928
929 return gtk_text_iter_get_offset(&iter) + x;
6de97a3b 930}
c801d85f 931
a81258be 932int wxTextCtrl::GetLineLength(long lineNo) const
c801d85f 933{
f29a481a
MR
934 if (m_windowStyle & wxTE_MULTILINE)
935 {
936 int last_line = gtk_text_buffer_get_line_count( m_buffer ) - 1;
937 if (lineNo > last_line)
938 return -1;
939
940 GtkTextIter iter;
941 gtk_text_buffer_get_iter_at_line(m_buffer, &iter, lineNo);
942 // get_chars_in_line return includes paragraph delimiters, so need to subtract 1 IF it is not the last line
943 return gtk_text_iter_get_chars_in_line(&iter) - ((lineNo == last_line) ? 0 : 1);
944 }
945 else
f29a481a
MR
946 {
947 wxString str = GetLineText (lineNo);
8e13c1ec 948 return (int) str.length();
f29a481a 949 }
6de97a3b 950}
c801d85f 951
a81258be 952int wxTextCtrl::GetNumberOfLines() const
c801d85f 953{
e894be20
VZ
954 if ( m_windowStyle & wxTE_MULTILINE )
955 {
956 GtkTextIter iter;
957 gtk_text_buffer_get_iter_at_offset( m_buffer, &iter, 0 );
958
959 // move forward by one display line until the end is reached
960 int lineCount = 1;
961 while ( gtk_text_view_forward_display_line(GTK_TEXT_VIEW(m_text), &iter) )
962 {
963 lineCount++;
964 }
965
966 // If the last character in the text buffer is a newline,
967 // gtk_text_view_forward_display_line() will return false without that
968 // line being counted. Must add one manually in that case.
8e13c1ec 969 GtkTextIter lastCharIter;
e894be20
VZ
970 gtk_text_buffer_get_iter_at_offset
971 (
972 m_buffer,
973 &lastCharIter,
974 gtk_text_buffer_get_char_count(m_buffer) - 1
975 );
976 gchar lastChar = gtk_text_iter_get_char( &lastCharIter );
977 if ( lastChar == wxT('\n') )
978 lineCount++;
979
980 return lineCount;
981 }
982 else // single line
983 {
96385642 984 return 1;
e894be20 985 }
6de97a3b 986}
c801d85f 987
debe6624 988void wxTextCtrl::SetInsertionPoint( long pos )
c801d85f 989{
223d09f6 990 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
3358d36e 991
74c5a810 992 if ( IsMultiLine() )
291a8f20 993 {
fab591c5 994 GtkTextIter iter;
41b81aed
RR
995 gtk_text_buffer_get_iter_at_offset( m_buffer, &iter, pos );
996 gtk_text_buffer_place_cursor( m_buffer, &iter );
74c5a810
VZ
997 gtk_text_view_scroll_mark_onscreen
998 (
999 GTK_TEXT_VIEW(m_text),
41b81aed 1000 gtk_text_buffer_get_insert( m_buffer )
74c5a810 1001 );
ac0d36b5 1002 }
2830bf19 1003 else
291a8f20 1004 {
6f85e712 1005 // FIXME: Is the editable's cursor really uptodate without double set_position in GTK2?
afa7bd1e 1006 gtk_editable_set_position(GTK_EDITABLE(m_text), int(pos));
291a8f20 1007 }
6de97a3b 1008}
c801d85f 1009
03f38c58 1010void wxTextCtrl::SetInsertionPointEnd()
c801d85f 1011{
223d09f6 1012 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 1013
d59051dd 1014 if (m_windowStyle & wxTE_MULTILINE)
fab591c5 1015 {
fab591c5 1016 GtkTextIter end;
41b81aed
RR
1017 gtk_text_buffer_get_end_iter( m_buffer, &end );
1018 gtk_text_buffer_place_cursor( m_buffer, &end );
fab591c5 1019 }
d59051dd 1020 else
fab591c5 1021 {
6f85e712 1022 gtk_editable_set_position( GTK_EDITABLE(m_text), -1 );
fab591c5 1023 }
6de97a3b 1024}
c801d85f 1025
debe6624 1026void wxTextCtrl::SetEditable( bool editable )
c801d85f 1027{
223d09f6 1028 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 1029
2830bf19 1030 if (m_windowStyle & wxTE_MULTILINE)
fab591c5 1031 {
fab591c5 1032 gtk_text_view_set_editable( GTK_TEXT_VIEW(m_text), editable );
fab591c5 1033 }
2830bf19 1034 else
fab591c5 1035 {
6f85e712 1036 gtk_editable_set_editable( GTK_EDITABLE(m_text), editable );
fab591c5 1037 }
6de97a3b 1038}
c801d85f 1039
68df5777
RR
1040bool wxTextCtrl::Enable( bool enable )
1041{
1042 if (!wxWindowBase::Enable(enable))
1043 {
1044 // nothing to do
7d8268a1 1045 return false;
68df5777 1046 }
f6bcfd97 1047
68df5777
RR
1048 if (m_windowStyle & wxTE_MULTILINE)
1049 {
fab591c5 1050 SetEditable( enable );
68df5777
RR
1051 }
1052 else
1053 {
1054 gtk_widget_set_sensitive( m_text, enable );
1055 }
1056
7d8268a1 1057 return true;
68df5777
RR
1058}
1059
fdca68a6
JS
1060// wxGTK-specific: called recursively by Enable,
1061// to give widgets an oppprtunity to correct their colours after they
1062// have been changed by Enable
1063void wxTextCtrl::OnParentEnable( bool enable )
1064{
1065 // If we have a custom background colour, we use this colour in both
1066 // disabled and enabled mode, or we end up with a different colour under the
1067 // text.
1068 wxColour oldColour = GetBackgroundColour();
1069 if (oldColour.Ok())
1070 {
1071 // Need to set twice or it'll optimize the useful stuff out
1072 if (oldColour == * wxWHITE)
1073 SetBackgroundColour(*wxBLACK);
1074 else
1075 SetBackgroundColour(*wxWHITE);
1076 SetBackgroundColour(oldColour);
1077 }
1078}
1079
3a9fa0d6
VZ
1080void wxTextCtrl::MarkDirty()
1081{
7d8268a1 1082 m_modified = true;
3a9fa0d6
VZ
1083}
1084
0efe5ba7
VZ
1085void wxTextCtrl::DiscardEdits()
1086{
7d8268a1 1087 m_modified = false;
0efe5ba7
VZ
1088}
1089
ce2f50e3
VZ
1090// ----------------------------------------------------------------------------
1091// max text length support
1092// ----------------------------------------------------------------------------
1093
1094void wxTextCtrl::IgnoreNextTextUpdate()
1095{
7d8268a1 1096 m_ignoreNextUpdate = true;
ce2f50e3
VZ
1097}
1098
1099bool wxTextCtrl::IgnoreTextUpdate()
1100{
1101 if ( m_ignoreNextUpdate )
1102 {
7d8268a1 1103 m_ignoreNextUpdate = false;
ce2f50e3 1104
7d8268a1 1105 return true;
ce2f50e3
VZ
1106 }
1107
7d8268a1 1108 return false;
ce2f50e3
VZ
1109}
1110
d7eee191
VZ
1111void wxTextCtrl::SetMaxLength(unsigned long len)
1112{
1113 if ( !HasFlag(wxTE_MULTILINE) )
1114 {
1115 gtk_entry_set_max_length(GTK_ENTRY(m_text), len);
ce2f50e3
VZ
1116
1117 // there is a bug in GTK+ 1.2.x: "changed" signal is emitted even if
1118 // we had tried to enter more text than allowed by max text length and
1119 // the text wasn't really changed
1120 //
1121 // to detect this and generate TEXT_MAXLEN event instead of
1122 // TEXT_CHANGED one in this case we also catch "insert_text" signal
1123 //
1124 // when max len is set to 0 we disconnect our handler as it means that
1125 // we shouldn't check anything any more
1126 if ( len )
1127 {
9fa72bd2
MR
1128 g_signal_connect (m_text, "insert_text",
1129 G_CALLBACK (gtk_insert_text_callback), this);
ce2f50e3
VZ
1130 }
1131 else // no checking
1132 {
9fa72bd2
MR
1133 g_signal_handlers_disconnect_by_func (m_text,
1134 (gpointer) gtk_insert_text_callback, this);
ce2f50e3 1135 }
d7eee191
VZ
1136 }
1137}
1138
debe6624 1139void wxTextCtrl::SetSelection( long from, long to )
c801d85f 1140{
223d09f6 1141 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 1142
2b5f62a0
VZ
1143 if (from == -1 && to == -1)
1144 {
1145 from = 0;
8e13c1ec 1146 to = GetValue().length();
2b5f62a0
VZ
1147 }
1148
fab591c5
RR
1149 if (m_windowStyle & wxTE_MULTILINE)
1150 {
739e366a 1151 GtkTextIter fromi, toi;
41b81aed
RR
1152 gtk_text_buffer_get_iter_at_offset( m_buffer, &fromi, from );
1153 gtk_text_buffer_get_iter_at_offset( m_buffer, &toi, to );
739e366a 1154
41b81aed
RR
1155 gtk_text_buffer_place_cursor( m_buffer, &toi );
1156 gtk_text_buffer_move_mark_by_name( m_buffer, "selection_bound", &fromi );
fab591c5
RR
1157 }
1158 else
1159 {
1160 gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to );
1161 }
6de97a3b 1162}
c801d85f 1163
afbe906a 1164void wxTextCtrl::ShowPosition( long pos )
c801d85f 1165{
afbe906a
RR
1166 if (m_windowStyle & wxTE_MULTILINE)
1167 {
71aba833 1168 GtkTextIter iter;
41b81aed 1169 gtk_text_buffer_get_start_iter( m_buffer, &iter );
71aba833 1170 gtk_text_iter_set_offset( &iter, pos );
41b81aed 1171 GtkTextMark *mark = gtk_text_buffer_create_mark( m_buffer, NULL, &iter, TRUE );
71aba833 1172 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text), mark, 0.0, FALSE, 0.0, 0.0 );
afbe906a 1173 }
6de97a3b 1174}
c801d85f 1175
692c9b86
VZ
1176wxTextCtrlHitTestResult
1177wxTextCtrl::HitTest(const wxPoint& pt, long *pos) const
1178{
1179 if ( !IsMultiLine() )
1180 {
1181 // not supported
1182 return wxTE_HT_UNKNOWN;
1183 }
1184
1185 int x, y;
1186 gtk_text_view_window_to_buffer_coords
1187 (
1188 GTK_TEXT_VIEW(m_text),
1189 GTK_TEXT_WINDOW_TEXT,
1190 pt.x, pt.y,
1191 &x, &y
1192 );
1193
1194 GtkTextIter iter;
1195 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text), &iter, x, y);
1196 if ( pos )
1197 *pos = gtk_text_iter_get_offset(&iter);
1198
1199 return wxTE_HT_ON_TEXT;
1200}
1201
03f38c58 1202long wxTextCtrl::GetInsertionPoint() const
c801d85f 1203{
223d09f6 1204 wxCHECK_MSG( m_text != NULL, 0, wxT("invalid text ctrl") );
8bbe427f 1205
fab591c5
RR
1206 if (m_windowStyle & wxTE_MULTILINE)
1207 {
fab591c5
RR
1208 // There is no direct accessor for the cursor, but
1209 // internally, the cursor is the "mark" called
1210 // "insert" in the text view's btree structure.
a8bf1826 1211
41b81aed 1212 GtkTextMark *mark = gtk_text_buffer_get_insert( m_buffer );
fab591c5 1213 GtkTextIter cursor;
41b81aed 1214 gtk_text_buffer_get_iter_at_mark( m_buffer, &cursor, mark );
a8bf1826 1215
fab591c5
RR
1216 return gtk_text_iter_get_offset( &cursor );
1217 }
1218 else
fab591c5 1219 {
afa7bd1e 1220 return (long) gtk_editable_get_position(GTK_EDITABLE(m_text));
fab591c5 1221 }
6de97a3b 1222}
c801d85f 1223
7d8268a1 1224wxTextPos wxTextCtrl::GetLastPosition() const
c801d85f 1225{
223d09f6 1226 wxCHECK_MSG( m_text != NULL, 0, wxT("invalid text ctrl") );
8bbe427f 1227
2830bf19 1228 int pos = 0;
a8bf1826 1229
2830bf19 1230 if (m_windowStyle & wxTE_MULTILINE)
fab591c5 1231 {
fab591c5 1232 GtkTextIter end;
41b81aed 1233 gtk_text_buffer_get_end_iter( m_buffer, &end );
a8bf1826 1234
fab591c5 1235 pos = gtk_text_iter_get_offset( &end );
fab591c5 1236 }
2830bf19 1237 else
fab591c5 1238 {
2830bf19 1239 pos = GTK_ENTRY(m_text)->text_length;
fab591c5 1240 }
805dd538 1241
ac0d36b5 1242 return (long)pos;
6de97a3b 1243}
c801d85f 1244
debe6624 1245void wxTextCtrl::Remove( long from, long to )
c801d85f 1246{
223d09f6 1247 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 1248
fdd55287 1249 if (m_windowStyle & wxTE_MULTILINE)
581ee8a9 1250 {
581ee8a9 1251 GtkTextIter fromi, toi;
41b81aed
RR
1252 gtk_text_buffer_get_iter_at_offset( m_buffer, &fromi, from );
1253 gtk_text_buffer_get_iter_at_offset( m_buffer, &toi, to );
581ee8a9 1254
41b81aed 1255 gtk_text_buffer_delete( m_buffer, &fromi, &toi );
581ee8a9
VZ
1256 }
1257 else // single line
68567a96 1258 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
6de97a3b 1259}
c801d85f 1260
debe6624 1261void wxTextCtrl::Replace( long from, long to, const wxString &value )
c801d85f 1262{
223d09f6 1263 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 1264
581ee8a9 1265 Remove( from, to );
bb69661b 1266
7d8268a1 1267 if (!value.empty())
2df7be7f 1268 {
581ee8a9
VZ
1269 SetInsertionPoint( from );
1270 WriteText( value );
2df7be7f 1271 }
6de97a3b 1272}
c801d85f 1273
03f38c58 1274void wxTextCtrl::Cut()
c801d85f 1275{
223d09f6 1276 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 1277
bbde2e29 1278 if (m_windowStyle & wxTE_MULTILINE)
9fa72bd2 1279 g_signal_emit_by_name (m_text, "cut-clipboard");
bbde2e29 1280 else
afa7bd1e 1281 gtk_editable_cut_clipboard(GTK_EDITABLE(m_text));
6de97a3b 1282}
c801d85f 1283
03f38c58 1284void wxTextCtrl::Copy()
c801d85f 1285{
223d09f6 1286 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 1287
bbde2e29 1288 if (m_windowStyle & wxTE_MULTILINE)
9fa72bd2 1289 g_signal_emit_by_name (m_text, "copy-clipboard");
bbde2e29 1290 else
afa7bd1e 1291 gtk_editable_copy_clipboard(GTK_EDITABLE(m_text));
6de97a3b 1292}
c801d85f 1293
03f38c58 1294void wxTextCtrl::Paste()
c801d85f 1295{
223d09f6 1296 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
8bbe427f 1297
bbde2e29 1298 if (m_windowStyle & wxTE_MULTILINE)
9fa72bd2 1299 g_signal_emit_by_name (m_text, "paste-clipboard");
bbde2e29 1300 else
afa7bd1e 1301 gtk_editable_paste_clipboard(GTK_EDITABLE(m_text));
6de97a3b 1302}
c801d85f 1303
ca8b28f2
JS
1304// Undo/redo
1305void wxTextCtrl::Undo()
1306{
1307 // TODO
223d09f6 1308 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
ca8b28f2
JS
1309}
1310
1311void wxTextCtrl::Redo()
1312{
1313 // TODO
223d09f6 1314 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
ca8b28f2
JS
1315}
1316
1317bool wxTextCtrl::CanUndo() const
1318{
1319 // TODO
4855a477 1320 //wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
7d8268a1 1321 return false;
ca8b28f2
JS
1322}
1323
1324bool wxTextCtrl::CanRedo() const
1325{
1326 // TODO
4855a477 1327 //wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
7d8268a1 1328 return false;
ca8b28f2
JS
1329}
1330
1331// If the return values from and to are the same, there is no
1332// selection.
2d4cc5b6 1333void wxTextCtrl::GetSelection(long* fromOut, long* toOut) const
ca8b28f2 1334{
223d09f6 1335 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
bb69661b 1336
5b87f8bf
RD
1337 gint from = -1;
1338 gint to = -1;
7d8268a1 1339 bool haveSelection = false;
5b87f8bf 1340
5b87f8bf
RD
1341 if (m_windowStyle & wxTE_MULTILINE)
1342 {
5b87f8bf 1343 GtkTextIter ifrom, ito;
41b81aed 1344 if ( gtk_text_buffer_get_selection_bounds(m_buffer, &ifrom, &ito) )
5b87f8bf 1345 {
7d8268a1 1346 haveSelection = true;
5b87f8bf
RD
1347 from = gtk_text_iter_get_offset(&ifrom);
1348 to = gtk_text_iter_get_offset(&ito);
1349 }
1350 }
1351 else // not multi-line
1352 {
1353 if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text),
1354 &from, &to) )
1355 {
7d8268a1 1356 haveSelection = true;
5b87f8bf
RD
1357 }
1358 }
2d4cc5b6 1359
5b87f8bf
RD
1360 if (! haveSelection )
1361 from = to = GetInsertionPoint();
1362
1363 if ( from > to )
1364 {
1365 // exchange them to be compatible with wxMSW
1366 gint tmp = from;
1367 from = to;
1368 to = tmp;
1369 }
bb69661b 1370
2d4cc5b6
VZ
1371 if ( fromOut )
1372 *fromOut = from;
1373 if ( toOut )
1374 *toOut = to;
ca8b28f2
JS
1375}
1376
5b87f8bf 1377
ca8b28f2
JS
1378bool wxTextCtrl::IsEditable() const
1379{
7d8268a1 1380 wxCHECK_MSG( m_text != NULL, false, wxT("invalid text ctrl") );
05060eeb 1381
fdd55287
VZ
1382 if (m_windowStyle & wxTE_MULTILINE)
1383 {
1384 return gtk_text_view_get_editable(GTK_TEXT_VIEW(m_text));
1385 }
1386 else
1387 {
1388 return gtk_editable_get_editable(GTK_EDITABLE(m_text));
1389 }
ca8b28f2
JS
1390}
1391
0efe5ba7
VZ
1392bool wxTextCtrl::IsModified() const
1393{
1394 return m_modified;
1395}
1396
03f38c58 1397void wxTextCtrl::Clear()
c801d85f 1398{
902725ee 1399 SetValue( wxEmptyString );
6de97a3b 1400}
c801d85f 1401
903f689b 1402void wxTextCtrl::OnChar( wxKeyEvent &key_event )
c801d85f 1403{
223d09f6 1404 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
805dd538 1405
8e13c1ec 1406 if ((key_event.GetKeyCode() == WXK_RETURN) && (m_windowStyle & wxTE_PROCESS_ENTER))
2830bf19
RR
1407 {
1408 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
1409 event.SetEventObject(this);
f6bcfd97 1410 event.SetString(GetValue());
2830bf19
RR
1411 if (GetEventHandler()->ProcessEvent(event)) return;
1412 }
903f689b 1413
12a3f227 1414 if ((key_event.GetKeyCode() == WXK_RETURN) && !(m_windowStyle & wxTE_MULTILINE))
da048e3d 1415 {
2b328fc9
RR
1416 // This will invoke the dialog default action, such
1417 // as the clicking the default button.
a8bf1826 1418
da048e3d 1419 wxWindow *top_frame = m_parent;
8487f887 1420 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
da048e3d 1421 top_frame = top_frame->GetParent();
a8bf1826 1422
2b328fc9 1423 if (top_frame && GTK_IS_WINDOW(top_frame->m_widget))
da048e3d 1424 {
2b328fc9
RR
1425 GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
1426
1427 if (window->default_widget)
1428 {
1429 gtk_widget_activate (window->default_widget);
1430 return;
1431 }
13111b2a 1432 }
da048e3d
RR
1433 }
1434
2830bf19 1435 key_event.Skip();
6de97a3b 1436}
c801d85f 1437
03f38c58 1438GtkWidget* wxTextCtrl::GetConnectWidget()
e3e65dac 1439{
ae0bdb01 1440 return GTK_WIDGET(m_text);
6de97a3b 1441}
e3e65dac 1442
903f689b
RR
1443bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
1444{
ae0bdb01 1445 if (m_windowStyle & wxTE_MULTILINE)
fab591c5 1446 {
fab591c5 1447 return window == gtk_text_view_get_window( GTK_TEXT_VIEW( m_text ), GTK_TEXT_WINDOW_TEXT ); // pure guesswork
fab591c5 1448 }
ae0bdb01 1449 else
fab591c5 1450 {
ae0bdb01 1451 return (window == GTK_ENTRY(m_text)->text_area);
fab591c5 1452 }
903f689b 1453}
e3e65dac 1454
bb69661b
VZ
1455// the font will change for subsequent text insertiongs
1456bool wxTextCtrl::SetFont( const wxFont &font )
868a2826 1457{
7d8268a1 1458 wxCHECK_MSG( m_text != NULL, false, wxT("invalid text ctrl") );
8bbe427f 1459
a66954a6 1460 if ( !wxTextCtrlBase::SetFont(font) )
bb69661b
VZ
1461 {
1462 // font didn't change, nothing to do
7d8268a1 1463 return false;
bb69661b
VZ
1464 }
1465
1466 if ( m_windowStyle & wxTE_MULTILINE )
1467 {
7d8268a1 1468 SetUpdateFont(true);
bb69661b 1469
1ff4714d
VZ
1470 m_defaultStyle.SetFont(font);
1471
01041145 1472 ChangeFontGlobally();
bb69661b
VZ
1473 }
1474
7d8268a1 1475 return true;
58614078
RR
1476}
1477
01041145
VZ
1478void wxTextCtrl::ChangeFontGlobally()
1479{
1480 // this method is very inefficient and hence should be called as rarely as
1481 // possible!
c04ec496
VZ
1482 //
1483 // TODO: it can be implemented much more efficiently for GTK2
22800f32
JS
1484 wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE),
1485 _T("shouldn't be called for single line controls") );
01041145
VZ
1486
1487 wxString value = GetValue();
7d8268a1 1488 if ( !value.empty() )
01041145 1489 {
7d8268a1 1490 SetUpdateFont(false);
572aeb77 1491
01041145
VZ
1492 Clear();
1493 AppendText(value);
01041145
VZ
1494 }
1495}
1496
17665a2b
VZ
1497bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
1498{
1499 if ( !wxControl::SetForegroundColour(colour) )
7d8268a1 1500 return false;
17665a2b
VZ
1501
1502 // update default fg colour too
1503 m_defaultStyle.SetTextColour(colour);
1504
7d8268a1 1505 return true;
17665a2b
VZ
1506}
1507
f03fc89f 1508bool wxTextCtrl::SetBackgroundColour( const wxColour &colour )
68dda785 1509{
7d8268a1 1510 wxCHECK_MSG( m_text != NULL, false, wxT("invalid text ctrl") );
a81258be 1511
1f477433 1512 if ( !wxControl::SetBackgroundColour( colour ) )
7d8268a1 1513 return false;
3358d36e 1514
f03fc89f 1515 if (!m_backgroundColour.Ok())
7d8268a1 1516 return false;
8bbe427f 1517
17665a2b
VZ
1518 // change active background color too
1519 m_defaultStyle.SetBackgroundColour( colour );
1520
7d8268a1 1521 return true;
58614078
RR
1522}
1523
eda40bfc 1524bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
17665a2b 1525{
17665a2b
VZ
1526 if ( m_windowStyle & wxTE_MULTILINE )
1527 {
1528 if ( style.IsDefault() )
1529 {
1530 // nothing to do
7d8268a1 1531 return true;
17665a2b 1532 }
902725ee 1533
41b81aed 1534 gint l = gtk_text_buffer_get_char_count( m_buffer );
17665a2b 1535
7d8268a1 1536 wxCHECK_MSG( start >= 0 && end <= l, false,
cc3da3f8
RR
1537 _T("invalid range in wxTextCtrl::SetStyle") );
1538
1539 GtkTextIter starti, endi;
41b81aed
RR
1540 gtk_text_buffer_get_iter_at_offset( m_buffer, &starti, start );
1541 gtk_text_buffer_get_iter_at_offset( m_buffer, &endi, end );
cc3da3f8
RR
1542
1543 // use the attributes from style which are set in it and fall back
1544 // first to the default style and then to the text control default
1545 // colours for the others
1546 wxTextAttr attr = wxTextAttr::Combine(style, m_defaultStyle, this);
1547
41b81aed 1548 wxGtkTextApplyTagsFromAttr( m_buffer, attr, &starti, &endi );
902725ee 1549
7d8268a1 1550 return true;
17665a2b 1551 }
902725ee
WS
1552
1553 // else single line
1554 // cannot do this for GTK+'s Entry widget
1555 return false;
17665a2b
VZ
1556}
1557
f40fdaa3 1558void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style)
58614078 1559{
f40fdaa3 1560 gtk_widget_modify_style(m_text, style);
68dda785 1561}
f96aa4d9 1562
e702ff0f
JS
1563void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
1564{
1565 Cut();
1566}
1567
1568void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
1569{
1570 Copy();
1571}
1572
1573void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
1574{
1575 Paste();
1576}
1577
1578void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
1579{
1580 Undo();
1581}
1582
1583void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
1584{
1585 Redo();
1586}
1587
1588void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
1589{
1590 event.Enable( CanCut() );
1591}
1592
1593void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
1594{
1595 event.Enable( CanCopy() );
1596}
1597
1598void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
1599{
1600 event.Enable( CanPaste() );
1601}
1602
1603void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
1604{
1605 event.Enable( CanUndo() );
1606}
1607
1608void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
1609{
1610 event.Enable( CanRedo() );
1611}
65045edd
RR
1612
1613void wxTextCtrl::OnInternalIdle()
1614{
1615 wxCursor cursor = m_cursor;
1616 if (g_globalCursor.Ok()) cursor = g_globalCursor;
1617
d7fa7eaa
RR
1618 if (g_delayedFocus == this)
1619 {
1620 if (GTK_WIDGET_REALIZED(m_widget))
1621 {
1622 gtk_widget_grab_focus( m_widget );
1623 g_delayedFocus = NULL;
1624 }
1625 }
1626
e39af974
JS
1627 if (wxUpdateUIEvent::CanUpdate(this))
1628 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
65045edd 1629}
f68586e5
VZ
1630
1631wxSize wxTextCtrl::DoGetBestSize() const
1632{
1633 // FIXME should be different for multi-line controls...
0279e844 1634 wxSize ret( wxControl::DoGetBestSize() );
9f884528
RD
1635 wxSize best(80, ret.y);
1636 CacheBestSize(best);
1637 return best;
f68586e5 1638}
0cc7251e 1639
9cd6d737
VZ
1640// ----------------------------------------------------------------------------
1641// freeze/thaw
1642// ----------------------------------------------------------------------------
1643
0cc7251e
VZ
1644void wxTextCtrl::Freeze()
1645{
1646 if ( HasFlag(wxTE_MULTILINE) )
1647 {
41b81aed
RR
1648 if ( !m_frozenness++ )
1649 {
1650 // freeze textview updates and remove buffer
9fa72bd2
MR
1651 g_signal_connect (m_text, "expose_event",
1652 G_CALLBACK (gtk_text_exposed_callback), this);
1653 g_signal_connect (m_widget, "expose_event",
1654 G_CALLBACK (gtk_text_exposed_callback), this);
41b81aed
RR
1655 gtk_widget_set_sensitive(m_widget, false);
1656 g_object_ref(m_buffer);
1657 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), gtk_text_buffer_new(NULL));
0a164d4c 1658 }
41b81aed 1659 }
0cc7251e
VZ
1660}
1661
1662void wxTextCtrl::Thaw()
1663{
1664 if ( HasFlag(wxTE_MULTILINE) )
1665 {
41b81aed
RR
1666 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
1667
1668 if ( !--m_frozenness )
1669 {
1670 // Reattach buffer and thaw textview updates
1671 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text), m_buffer);
1672 g_object_unref(m_buffer);
1673 gtk_widget_set_sensitive(m_widget, true);
9fa72bd2
MR
1674 g_signal_handlers_disconnect_by_func (m_widget,
1675 (gpointer) gtk_text_exposed_callback, this);
1676 g_signal_handlers_disconnect_by_func (m_text,
1677 (gpointer) gtk_text_exposed_callback, this);
41b81aed 1678 }
41b81aed 1679 }
0cc7251e 1680}
9cd6d737 1681
9440c3d0
KH
1682// ----------------------------------------------------------------------------
1683// wxTextUrlEvent passing if style & wxTE_AUTO_URL
1684// ----------------------------------------------------------------------------
1685
9440c3d0
KH
1686// FIXME: when dragging on a link the sample gets an "Unknown event".
1687// This might be an excessive event from us or a buggy wxMouseEvent::Moving() or
1688// a buggy sample, or something else
1689void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent& event)
1690{
1691 event.Skip();
1692 if(!(m_windowStyle & wxTE_AUTO_URL))
1693 return;
1694
1695 gint x, y;
1696 GtkTextIter start, end;
1697 GtkTextTag *tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(m_buffer),
1698 "wxUrl");
1699
1700 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(m_text), GTK_TEXT_WINDOW_WIDGET,
1701 event.GetX(), event.GetY(), &x, &y);
1702
1703 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text), &end, x, y);
1704 if (!gtk_text_iter_has_tag(&end, tag))
1705 {
1706 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text),
1707 GTK_TEXT_WINDOW_TEXT), m_gdkXTermCursor);
1708 return;
1709 }
1710
1711 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text),
1712 GTK_TEXT_WINDOW_TEXT), m_gdkHandCursor);
1713
1714 start = end;
1715 if(!gtk_text_iter_begins_tag(&start, tag))
1716 gtk_text_iter_backward_to_tag_toggle(&start, tag);
1717 if(!gtk_text_iter_ends_tag(&end, tag))
1718 gtk_text_iter_forward_to_tag_toggle(&end, tag);
1719
1720 // Native context menu is probably not desired on an URL.
1721 // Consider making this dependant on ProcessEvent(wxTextUrlEvent) return value
1722 if(event.GetEventType() == wxEVT_RIGHT_DOWN)
1723 event.Skip(false);
1724
1725 wxTextUrlEvent url_event(m_windowId, event,
1726 gtk_text_iter_get_offset(&start),
1727 gtk_text_iter_get_offset(&end));
1728
1729 InitCommandEvent(url_event);
1730 // Is that a good idea? Seems not (pleasure with gtk_text_view_start_selection_drag)
1731 //event.Skip(!GetEventHandler()->ProcessEvent(url_event));
1732 GetEventHandler()->ProcessEvent(url_event);
1733}
9440c3d0 1734
9d522606
RD
1735// static
1736wxVisualAttributes
1737wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
1738{
1739 return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true);
1740}