1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin, 2005 Mart Raudsepp
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #include "wx/textctrl.h"
18 #include "wx/settings.h"
20 #include "wx/strconv.h"
21 #include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
23 #include <sys/types.h>
28 #include "wx/gtk/private.h"
29 #include <gdk/gdkkeysyms.h>
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 extern void wxapp_install_idle_handler();
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 extern wxCursor g_globalCursor
;
43 extern wxWindowGTK
*g_delayedFocus
;
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
50 static void wxGtkOnRemoveTag(GtkTextBuffer
*buffer
,
57 g_object_get (tag
, "name", &name
, NULL
);
59 if (!name
|| strncmp(name
, prefix
, strlen(prefix
)))
60 // anonymous tag or not starting with prefix - don't remove
61 g_signal_stop_emission_by_name (buffer
, "remove_tag");
68 static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer
*text_buffer
,
69 const wxTextAttr
& attr
,
73 static gchar buf
[1024];
76 gulong remove_handler_id
= g_signal_connect (text_buffer
, "remove_tag",
77 G_CALLBACK (wxGtkOnRemoveTag
), gpointer("WX"));
78 gtk_text_buffer_remove_all_tags(text_buffer
, start
, end
);
79 g_signal_handler_disconnect (text_buffer
, remove_handler_id
);
84 PangoFontDescription
*font_description
= attr
.GetFont().GetNativeFontInfo()->description
;
85 font_string
= pango_font_description_to_string(font_description
);
86 g_snprintf(buf
, sizeof(buf
), "WXFONT %s", font_string
);
87 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
90 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
91 "font-desc", font_description
,
93 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
97 if (attr
.HasTextColour())
99 GdkColor
*colFg
= attr
.GetTextColour().GetColor();
100 g_snprintf(buf
, sizeof(buf
), "WXFORECOLOR %d %d %d",
101 colFg
->red
, colFg
->green
, colFg
->blue
);
102 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
105 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
106 "foreground-gdk", colFg
, NULL
);
107 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
110 if (attr
.HasBackgroundColour())
112 GdkColor
*colBg
= attr
.GetBackgroundColour().GetColor();
113 g_snprintf(buf
, sizeof(buf
), "WXBACKCOLOR %d %d %d",
114 colBg
->red
, colBg
->green
, colBg
->blue
);
115 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
118 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
119 "background-gdk", colBg
, NULL
);
120 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
123 if (attr
.HasAlignment())
125 GtkTextIter para_start
, para_end
= *end
;
126 gtk_text_buffer_get_iter_at_line( text_buffer
,
128 gtk_text_iter_get_line(start
) );
129 gtk_text_iter_forward_line(¶_end
);
131 remove_handler_id
= g_signal_connect (text_buffer
, "remove_tag",
132 G_CALLBACK(wxGtkOnRemoveTag
),
133 gpointer("WXALIGNMENT"));
134 gtk_text_buffer_remove_all_tags( text_buffer
, ¶_start
, ¶_end
);
135 g_signal_handler_disconnect (text_buffer
, remove_handler_id
);
137 GtkJustification align
;
138 switch (attr
.GetAlignment())
141 align
= GTK_JUSTIFY_LEFT
;
143 case wxTEXT_ALIGNMENT_RIGHT
:
144 align
= GTK_JUSTIFY_RIGHT
;
146 case wxTEXT_ALIGNMENT_CENTER
:
147 align
= GTK_JUSTIFY_CENTER
;
149 // gtk+ doesn't support justify as of gtk+-2.7.4
152 g_snprintf(buf
, sizeof(buf
), "WXALIGNMENT %d", align
);
153 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
156 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
157 "justification", align
, NULL
);
158 gtk_text_buffer_apply_tag( text_buffer
, tag
, ¶_start
, ¶_end
);
164 static void wxGtkTextInsert(GtkWidget
*text
,
165 GtkTextBuffer
*text_buffer
,
166 const wxTextAttr
& attr
,
167 const wxCharBuffer
& buffer
)
171 GtkTextIter iter
, start
;
173 gtk_text_buffer_get_iter_at_mark( text_buffer
, &iter
,
174 gtk_text_buffer_get_insert (text_buffer
) );
175 start_offset
= gtk_text_iter_get_offset (&iter
);
176 gtk_text_buffer_insert( text_buffer
, &iter
, buffer
, strlen(buffer
) );
178 gtk_text_buffer_get_iter_at_offset (text_buffer
, &start
, start_offset
);
180 wxGtkTextApplyTagsFromAttr(text_buffer
, attr
, &start
, &iter
);
184 // ----------------------------------------------------------------------------
185 // "insert_text" for GtkEntry
186 // ----------------------------------------------------------------------------
190 gtk_insert_text_callback(GtkEditable
*editable
,
191 const gchar
*new_text
,
192 gint new_text_length
,
197 wxapp_install_idle_handler();
199 // we should only be called if we have a max len limit at all
200 GtkEntry
*entry
= GTK_ENTRY (editable
);
202 wxCHECK_RET( entry
->text_max_length
, _T("shouldn't be called") );
204 // check that we don't overflow the max length limit
206 // FIXME: this doesn't work when we paste a string which is going to be
208 if ( entry
->text_length
== entry
->text_max_length
)
210 // we don't need to run the base class version at all
211 g_signal_stop_emission_by_name (editable
, "insert_text");
213 // remember that the next changed signal is to be ignored to avoid
214 // generating a dummy wxEVT_COMMAND_TEXT_UPDATED event
215 win
->IgnoreNextTextUpdate();
217 // and generate the correct one ourselves
218 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, win
->GetId());
219 event
.SetEventObject(win
);
220 event
.SetString(win
->GetValue());
221 win
->GetEventHandler()->ProcessEvent( event
);
226 // Implementation of wxTE_AUTO_URL for wxGTK2 by Mart Raudsepp,
230 au_apply_tag_callback(GtkTextBuffer
*buffer
,
236 if(tag
== gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl"))
237 g_signal_stop_emission_by_name (buffer
, "apply_tag");
241 //-----------------------------------------------------------------------------
242 // GtkTextCharPredicates for gtk_text_iter_*_find_char
243 //-----------------------------------------------------------------------------
247 pred_whitespace (gunichar ch
, gpointer user_data
)
249 return g_unichar_isspace(ch
);
255 pred_non_whitespace (gunichar ch
, gpointer user_data
)
257 return !g_unichar_isspace(ch
);
263 pred_nonpunct (gunichar ch
, gpointer user_data
)
265 return !g_unichar_ispunct(ch
);
271 pred_nonpunct_or_slash (gunichar ch
, gpointer user_data
)
273 return !g_unichar_ispunct(ch
) || ch
== '/';
277 //-----------------------------------------------------------------------------
278 // Check for links between s and e and correct tags as necessary
279 //-----------------------------------------------------------------------------
281 // This function should be made match better while being efficient at one point.
282 // Most probably with a row of regular expressions.
285 au_check_word( GtkTextIter
*s
, GtkTextIter
*e
)
287 static const char *URIPrefixes
[] =
305 GtkTextIter start
= *s
, end
= *e
;
306 GtkTextBuffer
*buffer
= gtk_text_iter_get_buffer(s
);
308 // Get our special link tag
309 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl");
311 // Get rid of punctuation from beginning and end.
312 // Might want to move this to au_check_range if an improved link checking doesn't
313 // use some intelligent punctuation checking itself (beware of undesired iter modifications).
314 if(g_unichar_ispunct( gtk_text_iter_get_char( &start
) ) )
315 gtk_text_iter_forward_find_char( &start
, pred_nonpunct
, NULL
, e
);
317 gtk_text_iter_backward_find_char( &end
, pred_nonpunct_or_slash
, NULL
, &start
);
318 gtk_text_iter_forward_char(&end
);
320 gchar
* text
= gtk_text_iter_get_text( &start
, &end
);
321 size_t len
= strlen(text
), prefix_len
;
324 for( n
= 0; n
< WXSIZEOF(URIPrefixes
); ++n
)
326 prefix_len
= strlen(URIPrefixes
[n
]);
327 if((len
> prefix_len
) && !strncasecmp(text
, URIPrefixes
[n
], prefix_len
))
331 if(n
< WXSIZEOF(URIPrefixes
))
333 gulong signal_id
= g_signal_handler_find (buffer
,
334 (GSignalMatchType
) (G_SIGNAL_MATCH_FUNC
),
336 (gpointer
)au_apply_tag_callback
, NULL
);
338 g_signal_handler_block (buffer
, signal_id
);
339 gtk_text_buffer_apply_tag(buffer
, tag
, &start
, &end
);
340 g_signal_handler_unblock (buffer
, signal_id
);
347 au_check_range(GtkTextIter
*s
,
348 GtkTextIter
*range_end
)
350 GtkTextIter range_start
= *s
;
351 GtkTextIter word_end
;
352 GtkTextBuffer
*buffer
= gtk_text_iter_get_buffer(s
);
353 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl");
355 gtk_text_buffer_remove_tag(buffer
, tag
, s
, range_end
);
357 if(g_unichar_isspace(gtk_text_iter_get_char(&range_start
)))
358 gtk_text_iter_forward_find_char(&range_start
, pred_non_whitespace
, NULL
, range_end
);
360 while(!gtk_text_iter_equal(&range_start
, range_end
))
362 word_end
= range_start
;
363 gtk_text_iter_forward_find_char(&word_end
, pred_whitespace
, NULL
, range_end
);
365 // Now we should have a word delimited by range_start and word_end, correct link tags
366 au_check_word(&range_start
, &word_end
);
368 range_start
= word_end
;
369 gtk_text_iter_forward_find_char(&range_start
, pred_non_whitespace
, NULL
, range_end
);
374 //-----------------------------------------------------------------------------
375 // "insert-text" for GtkTextBuffer
376 //-----------------------------------------------------------------------------
380 au_insert_text_callback(GtkTextBuffer
*buffer
,
386 if (!len
|| !(win
->GetWindowStyleFlag() & wxTE_AUTO_URL
) )
389 GtkTextIter start
= *end
;
390 gtk_text_iter_backward_chars(&start
, g_utf8_strlen(text
, len
));
392 GtkTextIter line_start
= start
;
393 GtkTextIter line_end
= *end
;
394 GtkTextIter words_start
= start
;
395 GtkTextIter words_end
= *end
;
397 gtk_text_iter_set_line(&line_start
, gtk_text_iter_get_line(&start
));
398 gtk_text_iter_forward_to_line_end(&line_end
);
399 gtk_text_iter_backward_find_char(&words_start
, pred_whitespace
, NULL
, &line_start
);
400 gtk_text_iter_forward_find_char(&words_end
, pred_whitespace
, NULL
, &line_end
);
402 au_check_range(&words_start
, &words_end
);
406 //-----------------------------------------------------------------------------
407 // "delete-range" for GtkTextBuffer
408 //-----------------------------------------------------------------------------
412 au_delete_range_callback(GtkTextBuffer
*buffer
,
417 if( !(win
->GetWindowStyleFlag() & wxTE_AUTO_URL
) )
420 GtkTextIter line_start
= *start
, line_end
= *end
;
422 gtk_text_iter_set_line(&line_start
, gtk_text_iter_get_line(start
));
423 gtk_text_iter_forward_to_line_end(&line_end
);
424 gtk_text_iter_backward_find_char(start
, pred_whitespace
, NULL
, &line_start
);
425 gtk_text_iter_forward_find_char(end
, pred_whitespace
, NULL
, &line_end
);
427 au_check_range(start
, end
);
432 //-----------------------------------------------------------------------------
434 //-----------------------------------------------------------------------------
438 gtk_text_changed_callback( GtkWidget
*widget
, wxTextCtrl
*win
)
440 if ( win
->IgnoreTextUpdate() )
443 if (!win
->m_hasVMT
) return;
446 wxapp_install_idle_handler();
450 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->GetId() );
451 event
.SetEventObject( win
);
452 win
->GetEventHandler()->ProcessEvent( event
);
456 //-----------------------------------------------------------------------------
457 // "expose_event" from scrolled window and textview
458 //-----------------------------------------------------------------------------
462 gtk_text_exposed_callback( GtkWidget
*widget
, GdkEventExpose
*event
, wxTextCtrl
*win
)
469 //-----------------------------------------------------------------------------
471 //-----------------------------------------------------------------------------
473 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
475 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
476 EVT_CHAR(wxTextCtrl::OnChar
)
478 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
479 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
480 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
481 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
482 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
484 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
485 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
486 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
487 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
488 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
490 // wxTE_AUTO_URL wxTextUrl support. Currently only creates
491 // wxTextUrlEvent in the same cases as wxMSW, more can be added here.
492 EVT_MOTION (wxTextCtrl::OnUrlMouseEvent
)
493 EVT_LEFT_DOWN (wxTextCtrl::OnUrlMouseEvent
)
494 EVT_LEFT_UP (wxTextCtrl::OnUrlMouseEvent
)
495 EVT_LEFT_DCLICK (wxTextCtrl::OnUrlMouseEvent
)
496 EVT_RIGHT_DOWN (wxTextCtrl::OnUrlMouseEvent
)
497 EVT_RIGHT_UP (wxTextCtrl::OnUrlMouseEvent
)
498 EVT_RIGHT_DCLICK(wxTextCtrl::OnUrlMouseEvent
)
501 void wxTextCtrl::Init()
505 SetUpdateFont(false);
507 m_vScrollbar
= (GtkWidget
*)NULL
;
509 m_gdkHandCursor
= NULL
;
510 m_gdkXTermCursor
= NULL
;
513 wxTextCtrl::~wxTextCtrl()
516 gdk_cursor_unref(m_gdkHandCursor
);
518 gdk_cursor_unref(m_gdkXTermCursor
);
521 wxTextCtrl::wxTextCtrl( wxWindow
*parent
,
523 const wxString
&value
,
527 const wxValidator
& validator
,
528 const wxString
&name
)
532 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
535 bool wxTextCtrl::Create( wxWindow
*parent
,
537 const wxString
&value
,
541 const wxValidator
& validator
,
542 const wxString
&name
)
545 m_acceptsFocus
= true;
547 if (!PreCreation( parent
, pos
, size
) ||
548 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
550 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
555 m_vScrollbarVisible
= false;
557 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
562 m_text
= gtk_text_view_new();
564 m_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
566 // create scrolled window
567 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
568 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget
),
569 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
571 // Insert view into scrolled window
572 gtk_container_add( GTK_CONTAINER(m_widget
), m_text
);
574 // translate wx wrapping style to GTK+
576 if ( HasFlag( wxTE_DONTWRAP
) )
577 wrap
= GTK_WRAP_NONE
;
578 else if ( HasFlag( wxTE_CHARWRAP
) )
579 wrap
= GTK_WRAP_CHAR
;
580 else if ( HasFlag( wxTE_WORDWRAP
) )
581 wrap
= GTK_WRAP_WORD
;
582 else // HasFlag(wxTE_BESTWRAP) always true as wxTE_BESTWRAP == 0
584 // GTK_WRAP_WORD_CHAR seems to be new in GTK+ 2.4
586 if ( !gtk_check_version(2,4,0) )
588 wrap
= GTK_WRAP_WORD_CHAR
;
592 wrap
= GTK_WRAP_WORD
;
595 gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text
), wrap
);
597 if (!HasFlag(wxNO_BORDER
))
598 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(m_widget
), GTK_SHADOW_IN
);
600 gtk_widget_add_events( GTK_WIDGET(m_text
), GDK_ENTER_NOTIFY_MASK
| GDK_LEAVE_NOTIFY_MASK
);
602 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
606 // a single-line text control: no need for scrollbars
608 m_text
= gtk_entry_new();
610 if (style
& wxNO_BORDER
)
611 g_object_set( GTK_ENTRY(m_text
), "has-frame", FALSE
, NULL
);
614 m_parent
->DoAddChild( this );
616 m_focusWidget
= m_text
;
622 gtk_widget_show(m_text
);
623 SetVScrollAdjustment(gtk_scrolled_window_get_vadjustment((GtkScrolledWindow
*)m_widget
));
631 if (style
& wxTE_PASSWORD
)
634 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
637 if (style
& wxTE_READONLY
)
640 gtk_editable_set_editable( GTK_EDITABLE(m_text
), FALSE
);
642 gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text
), FALSE
);
647 if (style
& wxTE_RIGHT
)
648 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_RIGHT
);
649 else if (style
& wxTE_CENTRE
)
650 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_CENTER
);
651 // Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
656 // gtk_entry_set_alignment was introduced in gtk+-2.3.5
657 if (!gtk_check_version(2,4,0))
659 if (style
& wxTE_RIGHT
)
660 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 1.0 );
661 else if (style
& wxTE_CENTRE
)
662 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 0.5 );
667 // We want to be notified about text changes.
670 g_signal_connect (m_buffer
, "changed",
671 G_CALLBACK (gtk_text_changed_callback
), this);
673 // .. and handle URLs on multi-line controls with wxTE_AUTO_URL style
674 if (style
& wxTE_AUTO_URL
)
676 GtkTextIter start
, end
;
677 m_gdkHandCursor
= gdk_cursor_new(GDK_HAND2
);
678 m_gdkXTermCursor
= gdk_cursor_new(GDK_XTERM
);
680 // We create our wxUrl tag here for slight efficiency gain - we
681 // don't have to check for the tag existance in callbacks,
682 // hereby it's guaranteed to exist.
683 gtk_text_buffer_create_tag(m_buffer
, "wxUrl",
684 "foreground", "blue",
685 "underline", PANGO_UNDERLINE_SINGLE
,
688 // Check for URLs after each text change
689 g_signal_connect_after (m_buffer
, "insert_text",
690 G_CALLBACK (au_insert_text_callback
), this);
691 g_signal_connect_after (m_buffer
, "delete_range",
692 G_CALLBACK (au_delete_range_callback
), this);
694 // Block all wxUrl tag applying unless we do it ourselves, in which case we
695 // block this callback temporarily. This takes care of gtk+ internal
696 // gtk_text_buffer_insert_range* calls that would copy our URL tag otherwise,
697 // which is undesired because only a part of the URL might be copied.
698 // The insert-text signal emitted inside it will take care of newly formed
699 // or wholly copied URLs.
700 g_signal_connect (m_buffer
, "apply_tag",
701 G_CALLBACK (au_apply_tag_callback
), NULL
);
703 // Check for URLs in the initial string passed to Create
704 gtk_text_buffer_get_start_iter(m_buffer
, &start
);
705 gtk_text_buffer_get_end_iter(m_buffer
, &end
);
706 au_check_range(&start
, &end
);
711 g_signal_connect (m_text
, "changed",
712 G_CALLBACK (gtk_text_changed_callback
), this);
715 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
717 wxTextAttr
attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont());
718 SetDefaultStyle( attrDef
);
724 void wxTextCtrl::CalculateScrollbar()
728 wxString
wxTextCtrl::GetValue() const
730 wxCHECK_MSG( m_text
!= NULL
, wxEmptyString
, wxT("invalid text ctrl") );
733 if (m_windowStyle
& wxTE_MULTILINE
)
736 gtk_text_buffer_get_start_iter( m_buffer
, &start
);
738 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
739 gchar
*text
= gtk_text_buffer_get_text( m_buffer
, &start
, &end
, TRUE
);
742 wxWCharBuffer
buffer( wxConvUTF8
.cMB2WX( text
) );
744 wxCharBuffer
buffer( wxConvLocal
.cWC2WX( wxConvUTF8
.cMB2WC( text
) ) );
753 tmp
= wxGTK_CONV_BACK( gtk_entry_get_text( GTK_ENTRY(m_text
) ) );
759 void wxTextCtrl::SetValue( const wxString
&value
)
761 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
763 if (m_windowStyle
& wxTE_MULTILINE
)
766 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( value
) );
768 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( value
) ) );
770 if (gtk_text_buffer_get_char_count(m_buffer
) != 0)
771 IgnoreNextTextUpdate();
775 // what else can we do? at least don't crash...
779 gtk_text_buffer_set_text( m_buffer
, buffer
, strlen(buffer
) );
783 gtk_entry_set_text( GTK_ENTRY(m_text
), wxGTK_CONV( value
) );
786 // GRG, Jun/2000: Changed this after a lot of discussion in
787 // the lists. wxWidgets 2.2 will have a set of flags to
788 // customize this behaviour.
789 SetInsertionPoint(0);
794 void wxTextCtrl::WriteText( const wxString
&text
)
796 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
801 // gtk_text_changed_callback() will set m_modified to true but m_modified
802 // shouldn't be changed by the program writing to the text control itself,
803 // so save the old value and restore when we're done
804 bool oldModified
= m_modified
;
806 if ( m_windowStyle
& wxTE_MULTILINE
)
809 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( text
) );
811 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) ) );
815 // what else can we do? at least don't crash...
819 // TODO: Call whatever is needed to delete the selection.
820 wxGtkTextInsert( m_text
, m_buffer
, m_defaultStyle
, buffer
);
822 GtkAdjustment
*adj
= gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(m_widget
) );
823 // Scroll to cursor, but only if scrollbar thumb is at the very bottom
824 if ( wxIsSameDouble(adj
->value
, adj
->upper
- adj
->page_size
) )
826 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
),
827 gtk_text_buffer_get_insert( m_buffer
), 0.0, FALSE
, 0.0, 1.0 );
832 // First remove the selection if there is one
833 gtk_editable_delete_selection( GTK_EDITABLE(m_text
) );
835 // This moves the cursor pos to behind the inserted text.
836 gint len
= gtk_editable_get_position(GTK_EDITABLE(m_text
));
839 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( text
) );
841 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) ) );
845 // what else can we do? at least don't crash...
849 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buffer
, strlen(buffer
), &len
);
851 // Bring entry's cursor uptodate.
852 gtk_editable_set_position( GTK_EDITABLE(m_text
), len
);
855 m_modified
= oldModified
;
858 void wxTextCtrl::AppendText( const wxString
&text
)
860 SetInsertionPointEnd();
864 wxString
wxTextCtrl::GetLineText( long lineNo
) const
866 if (m_windowStyle
& wxTE_MULTILINE
)
869 gtk_text_buffer_get_iter_at_line(m_buffer
,&line
,lineNo
);
870 GtkTextIter end
= line
;
871 gtk_text_iter_forward_to_line_end(&end
);
872 gchar
*text
= gtk_text_buffer_get_text(m_buffer
,&line
,&end
,TRUE
);
873 wxString
result(wxGTK_CONV_BACK(text
));
879 if (lineNo
== 0) return GetValue();
880 return wxEmptyString
;
884 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
886 /* If you implement this, don't forget to update the documentation!
887 * (file docs/latex/wx/text.tex) */
888 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
891 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
893 if ( m_windowStyle
& wxTE_MULTILINE
)
896 gtk_text_buffer_get_iter_at_offset(m_buffer
, &iter
, pos
);
897 if (gtk_text_iter_is_end(&iter
))
900 *y
= gtk_text_iter_get_line(&iter
);
901 *x
= gtk_text_iter_get_line_offset(&iter
);
903 else // single line control
905 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
912 // index out of bounds
920 long wxTextCtrl::XYToPosition(long x
, long y
) const
922 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
925 if (y
>= gtk_text_buffer_get_line_count (m_buffer
))
928 gtk_text_buffer_get_iter_at_line(m_buffer
, &iter
, y
);
929 if (x
>= gtk_text_iter_get_chars_in_line (&iter
))
932 return gtk_text_iter_get_offset(&iter
) + x
;
935 int wxTextCtrl::GetLineLength(long lineNo
) const
937 if (m_windowStyle
& wxTE_MULTILINE
)
939 int last_line
= gtk_text_buffer_get_line_count( m_buffer
) - 1;
940 if (lineNo
> last_line
)
944 gtk_text_buffer_get_iter_at_line(m_buffer
, &iter
, lineNo
);
945 // get_chars_in_line return includes paragraph delimiters, so need to subtract 1 IF it is not the last line
946 return gtk_text_iter_get_chars_in_line(&iter
) - ((lineNo
== last_line
) ? 0 : 1);
950 wxString str
= GetLineText (lineNo
);
951 return (int) str
.Length();
955 int wxTextCtrl::GetNumberOfLines() const
957 if (m_windowStyle
& wxTE_MULTILINE
)
958 return gtk_text_buffer_get_line_count( m_buffer
);
963 void wxTextCtrl::SetInsertionPoint( long pos
)
965 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
970 gtk_text_buffer_get_iter_at_offset( m_buffer
, &iter
, pos
);
971 gtk_text_buffer_place_cursor( m_buffer
, &iter
);
972 gtk_text_view_scroll_mark_onscreen
974 GTK_TEXT_VIEW(m_text
),
975 gtk_text_buffer_get_insert( m_buffer
)
980 // FIXME: Is the editable's cursor really uptodate without double set_position in GTK2?
981 gtk_editable_set_position(GTK_EDITABLE(m_text
), int(pos
));
985 void wxTextCtrl::SetInsertionPointEnd()
987 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
989 if (m_windowStyle
& wxTE_MULTILINE
)
992 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
993 gtk_text_buffer_place_cursor( m_buffer
, &end
);
997 gtk_editable_set_position( GTK_EDITABLE(m_text
), -1 );
1001 void wxTextCtrl::SetEditable( bool editable
)
1003 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1005 if (m_windowStyle
& wxTE_MULTILINE
)
1007 gtk_text_view_set_editable( GTK_TEXT_VIEW(m_text
), editable
);
1011 gtk_editable_set_editable( GTK_EDITABLE(m_text
), editable
);
1015 bool wxTextCtrl::Enable( bool enable
)
1017 if (!wxWindowBase::Enable(enable
))
1023 if (m_windowStyle
& wxTE_MULTILINE
)
1025 SetEditable( enable
);
1029 gtk_widget_set_sensitive( m_text
, enable
);
1035 // wxGTK-specific: called recursively by Enable,
1036 // to give widgets an oppprtunity to correct their colours after they
1037 // have been changed by Enable
1038 void wxTextCtrl::OnParentEnable( bool enable
)
1040 // If we have a custom background colour, we use this colour in both
1041 // disabled and enabled mode, or we end up with a different colour under the
1043 wxColour oldColour
= GetBackgroundColour();
1046 // Need to set twice or it'll optimize the useful stuff out
1047 if (oldColour
== * wxWHITE
)
1048 SetBackgroundColour(*wxBLACK
);
1050 SetBackgroundColour(*wxWHITE
);
1051 SetBackgroundColour(oldColour
);
1055 void wxTextCtrl::MarkDirty()
1060 void wxTextCtrl::DiscardEdits()
1065 // ----------------------------------------------------------------------------
1066 // max text length support
1067 // ----------------------------------------------------------------------------
1069 void wxTextCtrl::IgnoreNextTextUpdate()
1071 m_ignoreNextUpdate
= true;
1074 bool wxTextCtrl::IgnoreTextUpdate()
1076 if ( m_ignoreNextUpdate
)
1078 m_ignoreNextUpdate
= false;
1086 void wxTextCtrl::SetMaxLength(unsigned long len
)
1088 if ( !HasFlag(wxTE_MULTILINE
) )
1090 gtk_entry_set_max_length(GTK_ENTRY(m_text
), len
);
1092 // there is a bug in GTK+ 1.2.x: "changed" signal is emitted even if
1093 // we had tried to enter more text than allowed by max text length and
1094 // the text wasn't really changed
1096 // to detect this and generate TEXT_MAXLEN event instead of
1097 // TEXT_CHANGED one in this case we also catch "insert_text" signal
1099 // when max len is set to 0 we disconnect our handler as it means that
1100 // we shouldn't check anything any more
1103 g_signal_connect (m_text
, "insert_text",
1104 G_CALLBACK (gtk_insert_text_callback
), this);
1108 g_signal_handlers_disconnect_by_func (m_text
,
1109 (gpointer
) gtk_insert_text_callback
, this);
1114 void wxTextCtrl::SetSelection( long from
, long to
)
1116 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1118 if (from
== -1 && to
== -1)
1121 to
= GetValue().Length();
1124 if (m_windowStyle
& wxTE_MULTILINE
)
1126 GtkTextIter fromi
, toi
;
1127 gtk_text_buffer_get_iter_at_offset( m_buffer
, &fromi
, from
);
1128 gtk_text_buffer_get_iter_at_offset( m_buffer
, &toi
, to
);
1130 gtk_text_buffer_place_cursor( m_buffer
, &toi
);
1131 gtk_text_buffer_move_mark_by_name( m_buffer
, "selection_bound", &fromi
);
1135 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1139 void wxTextCtrl::ShowPosition( long pos
)
1141 if (m_windowStyle
& wxTE_MULTILINE
)
1144 gtk_text_buffer_get_start_iter( m_buffer
, &iter
);
1145 gtk_text_iter_set_offset( &iter
, pos
);
1146 GtkTextMark
*mark
= gtk_text_buffer_create_mark( m_buffer
, NULL
, &iter
, TRUE
);
1147 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
), mark
, 0.0, FALSE
, 0.0, 0.0 );
1151 wxTextCtrlHitTestResult
1152 wxTextCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
1154 if ( !IsMultiLine() )
1157 return wxTE_HT_UNKNOWN
;
1161 gtk_text_view_window_to_buffer_coords
1163 GTK_TEXT_VIEW(m_text
),
1164 GTK_TEXT_WINDOW_TEXT
,
1170 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &iter
, x
, y
);
1172 *pos
= gtk_text_iter_get_offset(&iter
);
1174 return wxTE_HT_ON_TEXT
;
1177 long wxTextCtrl::GetInsertionPoint() const
1179 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1181 if (m_windowStyle
& wxTE_MULTILINE
)
1183 // There is no direct accessor for the cursor, but
1184 // internally, the cursor is the "mark" called
1185 // "insert" in the text view's btree structure.
1187 GtkTextMark
*mark
= gtk_text_buffer_get_insert( m_buffer
);
1189 gtk_text_buffer_get_iter_at_mark( m_buffer
, &cursor
, mark
);
1191 return gtk_text_iter_get_offset( &cursor
);
1195 return (long) gtk_editable_get_position(GTK_EDITABLE(m_text
));
1199 wxTextPos
wxTextCtrl::GetLastPosition() const
1201 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1205 if (m_windowStyle
& wxTE_MULTILINE
)
1208 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
1210 pos
= gtk_text_iter_get_offset( &end
);
1214 pos
= GTK_ENTRY(m_text
)->text_length
;
1220 void wxTextCtrl::Remove( long from
, long to
)
1222 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1224 if (m_windowStyle
& wxTE_MULTILINE
)
1226 GtkTextIter fromi
, toi
;
1227 gtk_text_buffer_get_iter_at_offset( m_buffer
, &fromi
, from
);
1228 gtk_text_buffer_get_iter_at_offset( m_buffer
, &toi
, to
);
1230 gtk_text_buffer_delete( m_buffer
, &fromi
, &toi
);
1233 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1236 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
1238 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1244 SetInsertionPoint( from
);
1249 void wxTextCtrl::Cut()
1251 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1253 if (m_windowStyle
& wxTE_MULTILINE
)
1254 g_signal_emit_by_name (m_text
, "cut-clipboard");
1256 gtk_editable_cut_clipboard(GTK_EDITABLE(m_text
));
1259 void wxTextCtrl::Copy()
1261 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1263 if (m_windowStyle
& wxTE_MULTILINE
)
1264 g_signal_emit_by_name (m_text
, "copy-clipboard");
1266 gtk_editable_copy_clipboard(GTK_EDITABLE(m_text
));
1269 void wxTextCtrl::Paste()
1271 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1273 if (m_windowStyle
& wxTE_MULTILINE
)
1274 g_signal_emit_by_name (m_text
, "paste-clipboard");
1276 gtk_editable_paste_clipboard(GTK_EDITABLE(m_text
));
1280 void wxTextCtrl::Undo()
1283 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
1286 void wxTextCtrl::Redo()
1289 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
1292 bool wxTextCtrl::CanUndo() const
1295 //wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
1299 bool wxTextCtrl::CanRedo() const
1302 //wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
1306 // If the return values from and to are the same, there is no
1308 void wxTextCtrl::GetSelection(long* fromOut
, long* toOut
) const
1310 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1314 bool haveSelection
= false;
1316 if (m_windowStyle
& wxTE_MULTILINE
)
1318 GtkTextIter ifrom
, ito
;
1319 if ( gtk_text_buffer_get_selection_bounds(m_buffer
, &ifrom
, &ito
) )
1321 haveSelection
= true;
1322 from
= gtk_text_iter_get_offset(&ifrom
);
1323 to
= gtk_text_iter_get_offset(&ito
);
1326 else // not multi-line
1328 if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text
),
1331 haveSelection
= true;
1335 if (! haveSelection
)
1336 from
= to
= GetInsertionPoint();
1340 // exchange them to be compatible with wxMSW
1353 bool wxTextCtrl::IsEditable() const
1355 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1357 if (m_windowStyle
& wxTE_MULTILINE
)
1359 return gtk_text_view_get_editable(GTK_TEXT_VIEW(m_text
));
1363 return gtk_editable_get_editable(GTK_EDITABLE(m_text
));
1367 bool wxTextCtrl::IsModified() const
1372 void wxTextCtrl::Clear()
1374 SetValue( wxEmptyString
);
1377 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
1379 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1381 if ((key_event
.GetKeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
1383 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1384 event
.SetEventObject(this);
1385 event
.SetString(GetValue());
1386 if (GetEventHandler()->ProcessEvent(event
)) return;
1389 if ((key_event
.GetKeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
1391 // This will invoke the dialog default action, such
1392 // as the clicking the default button.
1394 wxWindow
*top_frame
= m_parent
;
1395 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
1396 top_frame
= top_frame
->GetParent();
1398 if (top_frame
&& GTK_IS_WINDOW(top_frame
->m_widget
))
1400 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
1402 if (window
->default_widget
)
1404 gtk_widget_activate (window
->default_widget
);
1413 GtkWidget
* wxTextCtrl::GetConnectWidget()
1415 return GTK_WIDGET(m_text
);
1418 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
1420 if (m_windowStyle
& wxTE_MULTILINE
)
1422 return window
== gtk_text_view_get_window( GTK_TEXT_VIEW( m_text
), GTK_TEXT_WINDOW_TEXT
); // pure guesswork
1426 return (window
== GTK_ENTRY(m_text
)->text_area
);
1430 // the font will change for subsequent text insertiongs
1431 bool wxTextCtrl::SetFont( const wxFont
&font
)
1433 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1435 if ( !wxTextCtrlBase::SetFont(font
) )
1437 // font didn't change, nothing to do
1441 if ( m_windowStyle
& wxTE_MULTILINE
)
1443 SetUpdateFont(true);
1445 m_defaultStyle
.SetFont(font
);
1447 ChangeFontGlobally();
1453 void wxTextCtrl::ChangeFontGlobally()
1455 // this method is very inefficient and hence should be called as rarely as
1458 // TODO: it can be implemented much more efficiently for GTK2
1459 wxASSERT_MSG( (m_windowStyle
& wxTE_MULTILINE
),
1460 _T("shouldn't be called for single line controls") );
1462 wxString value
= GetValue();
1463 if ( !value
.empty() )
1465 SetUpdateFont(false);
1472 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
1474 if ( !wxControl::SetForegroundColour(colour
) )
1477 // update default fg colour too
1478 m_defaultStyle
.SetTextColour(colour
);
1483 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
1485 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1487 if ( !wxControl::SetBackgroundColour( colour
) )
1490 if (!m_backgroundColour
.Ok())
1493 // change active background color too
1494 m_defaultStyle
.SetBackgroundColour( colour
);
1499 bool wxTextCtrl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1501 if ( m_windowStyle
& wxTE_MULTILINE
)
1503 if ( style
.IsDefault() )
1509 gint l
= gtk_text_buffer_get_char_count( m_buffer
);
1511 wxCHECK_MSG( start
>= 0 && end
<= l
, false,
1512 _T("invalid range in wxTextCtrl::SetStyle") );
1514 GtkTextIter starti
, endi
;
1515 gtk_text_buffer_get_iter_at_offset( m_buffer
, &starti
, start
);
1516 gtk_text_buffer_get_iter_at_offset( m_buffer
, &endi
, end
);
1518 // use the attributes from style which are set in it and fall back
1519 // first to the default style and then to the text control default
1520 // colours for the others
1521 wxTextAttr attr
= wxTextAttr::Combine(style
, m_defaultStyle
, this);
1523 wxGtkTextApplyTagsFromAttr( m_buffer
, attr
, &starti
, &endi
);
1529 // cannot do this for GTK+'s Entry widget
1533 void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
1535 gtk_widget_modify_style(m_text
, style
);
1538 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1543 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1548 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1553 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1558 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1563 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1565 event
.Enable( CanCut() );
1568 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1570 event
.Enable( CanCopy() );
1573 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1575 event
.Enable( CanPaste() );
1578 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1580 event
.Enable( CanUndo() );
1583 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1585 event
.Enable( CanRedo() );
1588 void wxTextCtrl::OnInternalIdle()
1590 wxCursor cursor
= m_cursor
;
1591 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1593 if (g_delayedFocus
== this)
1595 if (GTK_WIDGET_REALIZED(m_widget
))
1597 gtk_widget_grab_focus( m_widget
);
1598 g_delayedFocus
= NULL
;
1602 if (wxUpdateUIEvent::CanUpdate(this))
1603 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1606 wxSize
wxTextCtrl::DoGetBestSize() const
1608 // FIXME should be different for multi-line controls...
1609 wxSize
ret( wxControl::DoGetBestSize() );
1610 wxSize
best(80, ret
.y
);
1611 CacheBestSize(best
);
1615 // ----------------------------------------------------------------------------
1617 // ----------------------------------------------------------------------------
1619 void wxTextCtrl::Freeze()
1621 if ( HasFlag(wxTE_MULTILINE
) )
1623 if ( !m_frozenness
++ )
1625 // freeze textview updates and remove buffer
1626 g_signal_connect (m_text
, "expose_event",
1627 G_CALLBACK (gtk_text_exposed_callback
), this);
1628 g_signal_connect (m_widget
, "expose_event",
1629 G_CALLBACK (gtk_text_exposed_callback
), this);
1630 gtk_widget_set_sensitive(m_widget
, false);
1631 g_object_ref(m_buffer
);
1632 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text
), gtk_text_buffer_new(NULL
));
1637 void wxTextCtrl::Thaw()
1639 if ( HasFlag(wxTE_MULTILINE
) )
1641 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1643 if ( !--m_frozenness
)
1645 // Reattach buffer and thaw textview updates
1646 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text
), m_buffer
);
1647 g_object_unref(m_buffer
);
1648 gtk_widget_set_sensitive(m_widget
, true);
1649 g_signal_handlers_disconnect_by_func (m_widget
,
1650 (gpointer
) gtk_text_exposed_callback
, this);
1651 g_signal_handlers_disconnect_by_func (m_text
,
1652 (gpointer
) gtk_text_exposed_callback
, this);
1657 // ----------------------------------------------------------------------------
1658 // wxTextUrlEvent passing if style & wxTE_AUTO_URL
1659 // ----------------------------------------------------------------------------
1661 // FIXME: when dragging on a link the sample gets an "Unknown event".
1662 // This might be an excessive event from us or a buggy wxMouseEvent::Moving() or
1663 // a buggy sample, or something else
1664 void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent
& event
)
1667 if(!(m_windowStyle
& wxTE_AUTO_URL
))
1671 GtkTextIter start
, end
;
1672 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(m_buffer
),
1675 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(m_text
), GTK_TEXT_WINDOW_WIDGET
,
1676 event
.GetX(), event
.GetY(), &x
, &y
);
1678 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &end
, x
, y
);
1679 if (!gtk_text_iter_has_tag(&end
, tag
))
1681 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text
),
1682 GTK_TEXT_WINDOW_TEXT
), m_gdkXTermCursor
);
1686 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text
),
1687 GTK_TEXT_WINDOW_TEXT
), m_gdkHandCursor
);
1690 if(!gtk_text_iter_begins_tag(&start
, tag
))
1691 gtk_text_iter_backward_to_tag_toggle(&start
, tag
);
1692 if(!gtk_text_iter_ends_tag(&end
, tag
))
1693 gtk_text_iter_forward_to_tag_toggle(&end
, tag
);
1695 // Native context menu is probably not desired on an URL.
1696 // Consider making this dependant on ProcessEvent(wxTextUrlEvent) return value
1697 if(event
.GetEventType() == wxEVT_RIGHT_DOWN
)
1700 wxTextUrlEvent
url_event(m_windowId
, event
,
1701 gtk_text_iter_get_offset(&start
),
1702 gtk_text_iter_get_offset(&end
));
1704 InitCommandEvent(url_event
);
1705 // Is that a good idea? Seems not (pleasure with gtk_text_view_start_selection_drag)
1706 //event.Skip(!GetEventHandler()->ProcessEvent(url_event));
1707 GetEventHandler()->ProcessEvent(url_event
);
1712 wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1714 return GetDefaultAttributesFromGTKWidget(gtk_entry_new
, true);