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 wxCursor g_globalCursor
;
36 extern wxWindowGTK
*g_delayedFocus
;
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
43 static void wxGtkOnRemoveTag(GtkTextBuffer
*buffer
,
50 g_object_get (tag
, "name", &name
, NULL
);
52 if (!name
|| strncmp(name
, prefix
, strlen(prefix
)))
53 // anonymous tag or not starting with prefix - don't remove
54 g_signal_stop_emission_by_name (buffer
, "remove_tag");
61 static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer
*text_buffer
,
62 const wxTextAttr
& attr
,
66 static gchar buf
[1024];
69 gulong remove_handler_id
= g_signal_connect (text_buffer
, "remove_tag",
70 G_CALLBACK (wxGtkOnRemoveTag
), gpointer("WX"));
71 gtk_text_buffer_remove_all_tags(text_buffer
, start
, end
);
72 g_signal_handler_disconnect (text_buffer
, remove_handler_id
);
77 PangoFontDescription
*font_description
= attr
.GetFont().GetNativeFontInfo()->description
;
78 font_string
= pango_font_description_to_string(font_description
);
79 g_snprintf(buf
, sizeof(buf
), "WXFONT %s", font_string
);
80 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
83 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
84 "font-desc", font_description
,
86 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
90 if (attr
.HasTextColour())
92 GdkColor
*colFg
= attr
.GetTextColour().GetColor();
93 g_snprintf(buf
, sizeof(buf
), "WXFORECOLOR %d %d %d",
94 colFg
->red
, colFg
->green
, colFg
->blue
);
95 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
98 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
99 "foreground-gdk", colFg
, NULL
);
100 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
103 if (attr
.HasBackgroundColour())
105 GdkColor
*colBg
= attr
.GetBackgroundColour().GetColor();
106 g_snprintf(buf
, sizeof(buf
), "WXBACKCOLOR %d %d %d",
107 colBg
->red
, colBg
->green
, colBg
->blue
);
108 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
111 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
112 "background-gdk", colBg
, NULL
);
113 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
116 if (attr
.HasAlignment())
118 GtkTextIter para_start
, para_end
= *end
;
119 gtk_text_buffer_get_iter_at_line( text_buffer
,
121 gtk_text_iter_get_line(start
) );
122 gtk_text_iter_forward_line(¶_end
);
124 remove_handler_id
= g_signal_connect (text_buffer
, "remove_tag",
125 G_CALLBACK(wxGtkOnRemoveTag
),
126 gpointer("WXALIGNMENT"));
127 gtk_text_buffer_remove_all_tags( text_buffer
, ¶_start
, ¶_end
);
128 g_signal_handler_disconnect (text_buffer
, remove_handler_id
);
130 GtkJustification align
;
131 switch (attr
.GetAlignment())
134 align
= GTK_JUSTIFY_LEFT
;
136 case wxTEXT_ALIGNMENT_RIGHT
:
137 align
= GTK_JUSTIFY_RIGHT
;
139 case wxTEXT_ALIGNMENT_CENTER
:
140 align
= GTK_JUSTIFY_CENTER
;
142 // gtk+ doesn't support justify as of gtk+-2.7.4
145 g_snprintf(buf
, sizeof(buf
), "WXALIGNMENT %d", align
);
146 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
149 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
150 "justification", align
, NULL
);
151 gtk_text_buffer_apply_tag( text_buffer
, tag
, ¶_start
, ¶_end
);
157 static void wxGtkTextInsert(GtkWidget
*text
,
158 GtkTextBuffer
*text_buffer
,
159 const wxTextAttr
& attr
,
160 const wxCharBuffer
& buffer
)
164 GtkTextIter iter
, start
;
166 gtk_text_buffer_get_iter_at_mark( text_buffer
, &iter
,
167 gtk_text_buffer_get_insert (text_buffer
) );
168 start_offset
= gtk_text_iter_get_offset (&iter
);
169 gtk_text_buffer_insert( text_buffer
, &iter
, buffer
, strlen(buffer
) );
171 gtk_text_buffer_get_iter_at_offset (text_buffer
, &start
, start_offset
);
173 wxGtkTextApplyTagsFromAttr(text_buffer
, attr
, &start
, &iter
);
177 // ----------------------------------------------------------------------------
178 // "insert_text" for GtkEntry
179 // ----------------------------------------------------------------------------
183 gtk_insert_text_callback(GtkEditable
*editable
,
184 const gchar
*new_text
,
185 gint new_text_length
,
190 wxapp_install_idle_handler();
192 // we should only be called if we have a max len limit at all
193 GtkEntry
*entry
= GTK_ENTRY (editable
);
195 wxCHECK_RET( entry
->text_max_length
, _T("shouldn't be called") );
197 // check that we don't overflow the max length limit
199 // FIXME: this doesn't work when we paste a string which is going to be
201 if ( entry
->text_length
== entry
->text_max_length
)
203 // we don't need to run the base class version at all
204 g_signal_stop_emission_by_name (editable
, "insert_text");
206 // remember that the next changed signal is to be ignored to avoid
207 // generating a dummy wxEVT_COMMAND_TEXT_UPDATED event
208 win
->IgnoreNextTextUpdate();
210 // and generate the correct one ourselves
211 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, win
->GetId());
212 event
.SetEventObject(win
);
213 event
.SetString(win
->GetValue());
214 win
->GetEventHandler()->ProcessEvent( event
);
219 // Implementation of wxTE_AUTO_URL for wxGTK2 by Mart Raudsepp,
223 au_apply_tag_callback(GtkTextBuffer
*buffer
,
229 if(tag
== gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl"))
230 g_signal_stop_emission_by_name (buffer
, "apply_tag");
234 //-----------------------------------------------------------------------------
235 // GtkTextCharPredicates for gtk_text_iter_*_find_char
236 //-----------------------------------------------------------------------------
240 pred_whitespace (gunichar ch
, gpointer user_data
)
242 return g_unichar_isspace(ch
);
248 pred_non_whitespace (gunichar ch
, gpointer user_data
)
250 return !g_unichar_isspace(ch
);
256 pred_nonpunct (gunichar ch
, gpointer user_data
)
258 return !g_unichar_ispunct(ch
);
264 pred_nonpunct_or_slash (gunichar ch
, gpointer user_data
)
266 return !g_unichar_ispunct(ch
) || ch
== '/';
270 //-----------------------------------------------------------------------------
271 // Check for links between s and e and correct tags as necessary
272 //-----------------------------------------------------------------------------
274 // This function should be made match better while being efficient at one point.
275 // Most probably with a row of regular expressions.
278 au_check_word( GtkTextIter
*s
, GtkTextIter
*e
)
280 static const char *URIPrefixes
[] =
298 GtkTextIter start
= *s
, end
= *e
;
299 GtkTextBuffer
*buffer
= gtk_text_iter_get_buffer(s
);
301 // Get our special link tag
302 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl");
304 // Get rid of punctuation from beginning and end.
305 // Might want to move this to au_check_range if an improved link checking doesn't
306 // use some intelligent punctuation checking itself (beware of undesired iter modifications).
307 if(g_unichar_ispunct( gtk_text_iter_get_char( &start
) ) )
308 gtk_text_iter_forward_find_char( &start
, pred_nonpunct
, NULL
, e
);
310 gtk_text_iter_backward_find_char( &end
, pred_nonpunct_or_slash
, NULL
, &start
);
311 gtk_text_iter_forward_char(&end
);
313 gchar
* text
= gtk_text_iter_get_text( &start
, &end
);
314 size_t len
= strlen(text
), prefix_len
;
317 for( n
= 0; n
< WXSIZEOF(URIPrefixes
); ++n
)
319 prefix_len
= strlen(URIPrefixes
[n
]);
320 if((len
> prefix_len
) && !strncasecmp(text
, URIPrefixes
[n
], prefix_len
))
324 if(n
< WXSIZEOF(URIPrefixes
))
326 gulong signal_id
= g_signal_handler_find (buffer
,
327 (GSignalMatchType
) (G_SIGNAL_MATCH_FUNC
),
329 (gpointer
)au_apply_tag_callback
, NULL
);
331 g_signal_handler_block (buffer
, signal_id
);
332 gtk_text_buffer_apply_tag(buffer
, tag
, &start
, &end
);
333 g_signal_handler_unblock (buffer
, signal_id
);
340 au_check_range(GtkTextIter
*s
,
341 GtkTextIter
*range_end
)
343 GtkTextIter range_start
= *s
;
344 GtkTextIter word_end
;
345 GtkTextBuffer
*buffer
= gtk_text_iter_get_buffer(s
);
346 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl");
348 gtk_text_buffer_remove_tag(buffer
, tag
, s
, range_end
);
350 if(g_unichar_isspace(gtk_text_iter_get_char(&range_start
)))
351 gtk_text_iter_forward_find_char(&range_start
, pred_non_whitespace
, NULL
, range_end
);
353 while(!gtk_text_iter_equal(&range_start
, range_end
))
355 word_end
= range_start
;
356 gtk_text_iter_forward_find_char(&word_end
, pred_whitespace
, NULL
, range_end
);
358 // Now we should have a word delimited by range_start and word_end, correct link tags
359 au_check_word(&range_start
, &word_end
);
361 range_start
= word_end
;
362 gtk_text_iter_forward_find_char(&range_start
, pred_non_whitespace
, NULL
, range_end
);
367 //-----------------------------------------------------------------------------
368 // "insert-text" for GtkTextBuffer
369 //-----------------------------------------------------------------------------
373 au_insert_text_callback(GtkTextBuffer
*buffer
,
379 if (!len
|| !(win
->GetWindowStyleFlag() & wxTE_AUTO_URL
) )
382 GtkTextIter start
= *end
;
383 gtk_text_iter_backward_chars(&start
, g_utf8_strlen(text
, len
));
385 GtkTextIter line_start
= start
;
386 GtkTextIter line_end
= *end
;
387 GtkTextIter words_start
= start
;
388 GtkTextIter words_end
= *end
;
390 gtk_text_iter_set_line(&line_start
, gtk_text_iter_get_line(&start
));
391 gtk_text_iter_forward_to_line_end(&line_end
);
392 gtk_text_iter_backward_find_char(&words_start
, pred_whitespace
, NULL
, &line_start
);
393 gtk_text_iter_forward_find_char(&words_end
, pred_whitespace
, NULL
, &line_end
);
395 au_check_range(&words_start
, &words_end
);
399 //-----------------------------------------------------------------------------
400 // "delete-range" for GtkTextBuffer
401 //-----------------------------------------------------------------------------
405 au_delete_range_callback(GtkTextBuffer
*buffer
,
410 if( !(win
->GetWindowStyleFlag() & wxTE_AUTO_URL
) )
413 GtkTextIter line_start
= *start
, line_end
= *end
;
415 gtk_text_iter_set_line(&line_start
, gtk_text_iter_get_line(start
));
416 gtk_text_iter_forward_to_line_end(&line_end
);
417 gtk_text_iter_backward_find_char(start
, pred_whitespace
, NULL
, &line_start
);
418 gtk_text_iter_forward_find_char(end
, pred_whitespace
, NULL
, &line_end
);
420 au_check_range(start
, end
);
425 //-----------------------------------------------------------------------------
427 //-----------------------------------------------------------------------------
431 gtk_text_changed_callback( GtkWidget
*widget
, wxTextCtrl
*win
)
433 if ( win
->IgnoreTextUpdate() )
436 if (!win
->m_hasVMT
) return;
439 wxapp_install_idle_handler();
443 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->GetId() );
444 event
.SetEventObject( win
);
445 win
->GetEventHandler()->ProcessEvent( event
);
449 //-----------------------------------------------------------------------------
450 // "expose_event" from scrolled window and textview
451 //-----------------------------------------------------------------------------
455 gtk_text_exposed_callback( GtkWidget
*widget
, GdkEventExpose
*event
, wxTextCtrl
*win
)
462 //-----------------------------------------------------------------------------
464 //-----------------------------------------------------------------------------
466 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
468 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
469 EVT_CHAR(wxTextCtrl::OnChar
)
471 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
472 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
473 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
474 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
475 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
477 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
478 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
479 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
480 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
481 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
483 // wxTE_AUTO_URL wxTextUrl support. Currently only creates
484 // wxTextUrlEvent in the same cases as wxMSW, more can be added here.
485 EVT_MOTION (wxTextCtrl::OnUrlMouseEvent
)
486 EVT_LEFT_DOWN (wxTextCtrl::OnUrlMouseEvent
)
487 EVT_LEFT_UP (wxTextCtrl::OnUrlMouseEvent
)
488 EVT_LEFT_DCLICK (wxTextCtrl::OnUrlMouseEvent
)
489 EVT_RIGHT_DOWN (wxTextCtrl::OnUrlMouseEvent
)
490 EVT_RIGHT_UP (wxTextCtrl::OnUrlMouseEvent
)
491 EVT_RIGHT_DCLICK(wxTextCtrl::OnUrlMouseEvent
)
494 void wxTextCtrl::Init()
498 SetUpdateFont(false);
500 m_vScrollbar
= (GtkWidget
*)NULL
;
502 m_gdkHandCursor
= NULL
;
503 m_gdkXTermCursor
= NULL
;
506 wxTextCtrl::~wxTextCtrl()
509 gdk_cursor_unref(m_gdkHandCursor
);
511 gdk_cursor_unref(m_gdkXTermCursor
);
514 wxTextCtrl::wxTextCtrl( wxWindow
*parent
,
516 const wxString
&value
,
520 const wxValidator
& validator
,
521 const wxString
&name
)
525 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
528 bool wxTextCtrl::Create( wxWindow
*parent
,
530 const wxString
&value
,
534 const wxValidator
& validator
,
535 const wxString
&name
)
538 m_acceptsFocus
= true;
540 if (!PreCreation( parent
, pos
, size
) ||
541 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
543 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
548 m_vScrollbarVisible
= false;
550 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
555 m_text
= gtk_text_view_new();
557 m_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
559 // create scrolled window
560 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
561 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget
),
562 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
564 // Insert view into scrolled window
565 gtk_container_add( GTK_CONTAINER(m_widget
), m_text
);
567 // translate wx wrapping style to GTK+
569 if ( HasFlag( wxTE_DONTWRAP
) )
570 wrap
= GTK_WRAP_NONE
;
571 else if ( HasFlag( wxTE_CHARWRAP
) )
572 wrap
= GTK_WRAP_CHAR
;
573 else if ( HasFlag( wxTE_WORDWRAP
) )
574 wrap
= GTK_WRAP_WORD
;
575 else // HasFlag(wxTE_BESTWRAP) always true as wxTE_BESTWRAP == 0
577 // GTK_WRAP_WORD_CHAR seems to be new in GTK+ 2.4
579 if ( !gtk_check_version(2,4,0) )
581 wrap
= GTK_WRAP_WORD_CHAR
;
585 wrap
= GTK_WRAP_WORD
;
588 gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text
), wrap
);
590 if (!HasFlag(wxNO_BORDER
))
591 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(m_widget
), GTK_SHADOW_IN
);
593 gtk_widget_add_events( GTK_WIDGET(m_text
), GDK_ENTER_NOTIFY_MASK
| GDK_LEAVE_NOTIFY_MASK
);
595 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
599 // a single-line text control: no need for scrollbars
601 m_text
= gtk_entry_new();
603 if (style
& wxNO_BORDER
)
604 g_object_set( GTK_ENTRY(m_text
), "has-frame", FALSE
, NULL
);
607 m_parent
->DoAddChild( this );
609 m_focusWidget
= m_text
;
615 gtk_widget_show(m_text
);
616 SetVScrollAdjustment(gtk_scrolled_window_get_vadjustment((GtkScrolledWindow
*)m_widget
));
624 if (style
& wxTE_PASSWORD
)
627 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
630 if (style
& wxTE_READONLY
)
633 gtk_editable_set_editable( GTK_EDITABLE(m_text
), FALSE
);
635 gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text
), FALSE
);
640 if (style
& wxTE_RIGHT
)
641 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_RIGHT
);
642 else if (style
& wxTE_CENTRE
)
643 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_CENTER
);
644 // Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
649 // gtk_entry_set_alignment was introduced in gtk+-2.3.5
650 if (!gtk_check_version(2,4,0))
652 if (style
& wxTE_RIGHT
)
653 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 1.0 );
654 else if (style
& wxTE_CENTRE
)
655 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 0.5 );
660 // We want to be notified about text changes.
663 g_signal_connect (m_buffer
, "changed",
664 G_CALLBACK (gtk_text_changed_callback
), this);
666 // .. and handle URLs on multi-line controls with wxTE_AUTO_URL style
667 if (style
& wxTE_AUTO_URL
)
669 GtkTextIter start
, end
;
670 m_gdkHandCursor
= gdk_cursor_new(GDK_HAND2
);
671 m_gdkXTermCursor
= gdk_cursor_new(GDK_XTERM
);
673 // We create our wxUrl tag here for slight efficiency gain - we
674 // don't have to check for the tag existance in callbacks,
675 // hereby it's guaranteed to exist.
676 gtk_text_buffer_create_tag(m_buffer
, "wxUrl",
677 "foreground", "blue",
678 "underline", PANGO_UNDERLINE_SINGLE
,
681 // Check for URLs after each text change
682 g_signal_connect_after (m_buffer
, "insert_text",
683 G_CALLBACK (au_insert_text_callback
), this);
684 g_signal_connect_after (m_buffer
, "delete_range",
685 G_CALLBACK (au_delete_range_callback
), this);
687 // Block all wxUrl tag applying unless we do it ourselves, in which case we
688 // block this callback temporarily. This takes care of gtk+ internal
689 // gtk_text_buffer_insert_range* calls that would copy our URL tag otherwise,
690 // which is undesired because only a part of the URL might be copied.
691 // The insert-text signal emitted inside it will take care of newly formed
692 // or wholly copied URLs.
693 g_signal_connect (m_buffer
, "apply_tag",
694 G_CALLBACK (au_apply_tag_callback
), NULL
);
696 // Check for URLs in the initial string passed to Create
697 gtk_text_buffer_get_start_iter(m_buffer
, &start
);
698 gtk_text_buffer_get_end_iter(m_buffer
, &end
);
699 au_check_range(&start
, &end
);
704 g_signal_connect (m_text
, "changed",
705 G_CALLBACK (gtk_text_changed_callback
), this);
708 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
710 wxTextAttr
attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont());
711 SetDefaultStyle( attrDef
);
717 void wxTextCtrl::CalculateScrollbar()
721 wxString
wxTextCtrl::GetValue() const
723 wxCHECK_MSG( m_text
!= NULL
, wxEmptyString
, wxT("invalid text ctrl") );
726 if (m_windowStyle
& wxTE_MULTILINE
)
729 gtk_text_buffer_get_start_iter( m_buffer
, &start
);
731 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
732 gchar
*text
= gtk_text_buffer_get_text( m_buffer
, &start
, &end
, TRUE
);
735 wxWCharBuffer
buffer( wxConvUTF8
.cMB2WX( text
) );
737 wxCharBuffer
buffer( wxConvLocal
.cWC2WX( wxConvUTF8
.cMB2WC( text
) ) );
746 tmp
= wxGTK_CONV_BACK( gtk_entry_get_text( GTK_ENTRY(m_text
) ) );
752 void wxTextCtrl::SetValue( const wxString
&value
)
754 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
756 if (m_windowStyle
& wxTE_MULTILINE
)
759 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( value
) );
761 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( value
) ) );
763 if (gtk_text_buffer_get_char_count(m_buffer
) != 0)
764 IgnoreNextTextUpdate();
768 // what else can we do? at least don't crash...
772 gtk_text_buffer_set_text( m_buffer
, buffer
, strlen(buffer
) );
776 gtk_entry_set_text( GTK_ENTRY(m_text
), wxGTK_CONV( value
) );
779 // GRG, Jun/2000: Changed this after a lot of discussion in
780 // the lists. wxWidgets 2.2 will have a set of flags to
781 // customize this behaviour.
782 SetInsertionPoint(0);
787 void wxTextCtrl::WriteText( const wxString
&text
)
789 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
794 // gtk_text_changed_callback() will set m_modified to true but m_modified
795 // shouldn't be changed by the program writing to the text control itself,
796 // so save the old value and restore when we're done
797 bool oldModified
= m_modified
;
799 if ( m_windowStyle
& wxTE_MULTILINE
)
802 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( text
) );
804 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) ) );
808 // what else can we do? at least don't crash...
812 // TODO: Call whatever is needed to delete the selection.
813 wxGtkTextInsert( m_text
, m_buffer
, m_defaultStyle
, buffer
);
815 GtkAdjustment
*adj
= gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(m_widget
) );
816 // Scroll to cursor, but only if scrollbar thumb is at the very bottom
817 if ( wxIsSameDouble(adj
->value
, adj
->upper
- adj
->page_size
) )
819 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
),
820 gtk_text_buffer_get_insert( m_buffer
), 0.0, FALSE
, 0.0, 1.0 );
825 // First remove the selection if there is one
826 gtk_editable_delete_selection( GTK_EDITABLE(m_text
) );
828 // This moves the cursor pos to behind the inserted text.
829 gint len
= gtk_editable_get_position(GTK_EDITABLE(m_text
));
832 wxCharBuffer
buffer( wxConvUTF8
.cWX2MB( text
) );
834 wxCharBuffer
buffer( wxConvUTF8
.cWC2MB( wxConvLocal
.cWX2WC( text
) ) );
838 // what else can we do? at least don't crash...
842 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buffer
, strlen(buffer
), &len
);
844 // Bring entry's cursor uptodate.
845 gtk_editable_set_position( GTK_EDITABLE(m_text
), len
);
848 m_modified
= oldModified
;
851 void wxTextCtrl::AppendText( const wxString
&text
)
853 SetInsertionPointEnd();
857 wxString
wxTextCtrl::GetLineText( long lineNo
) const
859 if (m_windowStyle
& wxTE_MULTILINE
)
862 gtk_text_buffer_get_iter_at_line(m_buffer
,&line
,lineNo
);
863 GtkTextIter end
= line
;
864 gtk_text_iter_forward_to_line_end(&end
);
865 gchar
*text
= gtk_text_buffer_get_text(m_buffer
,&line
,&end
,TRUE
);
866 wxString
result(wxGTK_CONV_BACK(text
));
872 if (lineNo
== 0) return GetValue();
873 return wxEmptyString
;
877 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
879 /* If you implement this, don't forget to update the documentation!
880 * (file docs/latex/wx/text.tex) */
881 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
884 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
886 if ( m_windowStyle
& wxTE_MULTILINE
)
889 gtk_text_buffer_get_iter_at_offset(m_buffer
, &iter
, pos
);
890 if (gtk_text_iter_is_end(&iter
))
893 *y
= gtk_text_iter_get_line(&iter
);
894 *x
= gtk_text_iter_get_line_offset(&iter
);
896 else // single line control
898 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
905 // index out of bounds
913 long wxTextCtrl::XYToPosition(long x
, long y
) const
915 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
918 if (y
>= gtk_text_buffer_get_line_count (m_buffer
))
921 gtk_text_buffer_get_iter_at_line(m_buffer
, &iter
, y
);
922 if (x
>= gtk_text_iter_get_chars_in_line (&iter
))
925 return gtk_text_iter_get_offset(&iter
) + x
;
928 int wxTextCtrl::GetLineLength(long lineNo
) const
930 if (m_windowStyle
& wxTE_MULTILINE
)
932 int last_line
= gtk_text_buffer_get_line_count( m_buffer
) - 1;
933 if (lineNo
> last_line
)
937 gtk_text_buffer_get_iter_at_line(m_buffer
, &iter
, lineNo
);
938 // get_chars_in_line return includes paragraph delimiters, so need to subtract 1 IF it is not the last line
939 return gtk_text_iter_get_chars_in_line(&iter
) - ((lineNo
== last_line
) ? 0 : 1);
943 wxString str
= GetLineText (lineNo
);
944 return (int) str
.Length();
948 int wxTextCtrl::GetNumberOfLines() const
950 if (m_windowStyle
& wxTE_MULTILINE
)
951 return gtk_text_buffer_get_line_count( m_buffer
);
956 void wxTextCtrl::SetInsertionPoint( long pos
)
958 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
963 gtk_text_buffer_get_iter_at_offset( m_buffer
, &iter
, pos
);
964 gtk_text_buffer_place_cursor( m_buffer
, &iter
);
965 gtk_text_view_scroll_mark_onscreen
967 GTK_TEXT_VIEW(m_text
),
968 gtk_text_buffer_get_insert( m_buffer
)
973 // FIXME: Is the editable's cursor really uptodate without double set_position in GTK2?
974 gtk_editable_set_position(GTK_EDITABLE(m_text
), int(pos
));
978 void wxTextCtrl::SetInsertionPointEnd()
980 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
982 if (m_windowStyle
& wxTE_MULTILINE
)
985 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
986 gtk_text_buffer_place_cursor( m_buffer
, &end
);
990 gtk_editable_set_position( GTK_EDITABLE(m_text
), -1 );
994 void wxTextCtrl::SetEditable( bool editable
)
996 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
998 if (m_windowStyle
& wxTE_MULTILINE
)
1000 gtk_text_view_set_editable( GTK_TEXT_VIEW(m_text
), editable
);
1004 gtk_editable_set_editable( GTK_EDITABLE(m_text
), editable
);
1008 bool wxTextCtrl::Enable( bool enable
)
1010 if (!wxWindowBase::Enable(enable
))
1016 if (m_windowStyle
& wxTE_MULTILINE
)
1018 SetEditable( enable
);
1022 gtk_widget_set_sensitive( m_text
, enable
);
1028 // wxGTK-specific: called recursively by Enable,
1029 // to give widgets an oppprtunity to correct their colours after they
1030 // have been changed by Enable
1031 void wxTextCtrl::OnParentEnable( bool enable
)
1033 // If we have a custom background colour, we use this colour in both
1034 // disabled and enabled mode, or we end up with a different colour under the
1036 wxColour oldColour
= GetBackgroundColour();
1039 // Need to set twice or it'll optimize the useful stuff out
1040 if (oldColour
== * wxWHITE
)
1041 SetBackgroundColour(*wxBLACK
);
1043 SetBackgroundColour(*wxWHITE
);
1044 SetBackgroundColour(oldColour
);
1048 void wxTextCtrl::MarkDirty()
1053 void wxTextCtrl::DiscardEdits()
1058 // ----------------------------------------------------------------------------
1059 // max text length support
1060 // ----------------------------------------------------------------------------
1062 void wxTextCtrl::IgnoreNextTextUpdate()
1064 m_ignoreNextUpdate
= true;
1067 bool wxTextCtrl::IgnoreTextUpdate()
1069 if ( m_ignoreNextUpdate
)
1071 m_ignoreNextUpdate
= false;
1079 void wxTextCtrl::SetMaxLength(unsigned long len
)
1081 if ( !HasFlag(wxTE_MULTILINE
) )
1083 gtk_entry_set_max_length(GTK_ENTRY(m_text
), len
);
1085 // there is a bug in GTK+ 1.2.x: "changed" signal is emitted even if
1086 // we had tried to enter more text than allowed by max text length and
1087 // the text wasn't really changed
1089 // to detect this and generate TEXT_MAXLEN event instead of
1090 // TEXT_CHANGED one in this case we also catch "insert_text" signal
1092 // when max len is set to 0 we disconnect our handler as it means that
1093 // we shouldn't check anything any more
1096 g_signal_connect (m_text
, "insert_text",
1097 G_CALLBACK (gtk_insert_text_callback
), this);
1101 g_signal_handlers_disconnect_by_func (m_text
,
1102 (gpointer
) gtk_insert_text_callback
, this);
1107 void wxTextCtrl::SetSelection( long from
, long to
)
1109 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1111 if (from
== -1 && to
== -1)
1114 to
= GetValue().Length();
1117 if (m_windowStyle
& wxTE_MULTILINE
)
1119 GtkTextIter fromi
, toi
;
1120 gtk_text_buffer_get_iter_at_offset( m_buffer
, &fromi
, from
);
1121 gtk_text_buffer_get_iter_at_offset( m_buffer
, &toi
, to
);
1123 gtk_text_buffer_place_cursor( m_buffer
, &toi
);
1124 gtk_text_buffer_move_mark_by_name( m_buffer
, "selection_bound", &fromi
);
1128 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1132 void wxTextCtrl::ShowPosition( long pos
)
1134 if (m_windowStyle
& wxTE_MULTILINE
)
1137 gtk_text_buffer_get_start_iter( m_buffer
, &iter
);
1138 gtk_text_iter_set_offset( &iter
, pos
);
1139 GtkTextMark
*mark
= gtk_text_buffer_create_mark( m_buffer
, NULL
, &iter
, TRUE
);
1140 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
), mark
, 0.0, FALSE
, 0.0, 0.0 );
1144 wxTextCtrlHitTestResult
1145 wxTextCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
1147 if ( !IsMultiLine() )
1150 return wxTE_HT_UNKNOWN
;
1154 gtk_text_view_window_to_buffer_coords
1156 GTK_TEXT_VIEW(m_text
),
1157 GTK_TEXT_WINDOW_TEXT
,
1163 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &iter
, x
, y
);
1165 *pos
= gtk_text_iter_get_offset(&iter
);
1167 return wxTE_HT_ON_TEXT
;
1170 long wxTextCtrl::GetInsertionPoint() const
1172 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1174 if (m_windowStyle
& wxTE_MULTILINE
)
1176 // There is no direct accessor for the cursor, but
1177 // internally, the cursor is the "mark" called
1178 // "insert" in the text view's btree structure.
1180 GtkTextMark
*mark
= gtk_text_buffer_get_insert( m_buffer
);
1182 gtk_text_buffer_get_iter_at_mark( m_buffer
, &cursor
, mark
);
1184 return gtk_text_iter_get_offset( &cursor
);
1188 return (long) gtk_editable_get_position(GTK_EDITABLE(m_text
));
1192 wxTextPos
wxTextCtrl::GetLastPosition() const
1194 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1198 if (m_windowStyle
& wxTE_MULTILINE
)
1201 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
1203 pos
= gtk_text_iter_get_offset( &end
);
1207 pos
= GTK_ENTRY(m_text
)->text_length
;
1213 void wxTextCtrl::Remove( long from
, long to
)
1215 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1217 if (m_windowStyle
& wxTE_MULTILINE
)
1219 GtkTextIter fromi
, toi
;
1220 gtk_text_buffer_get_iter_at_offset( m_buffer
, &fromi
, from
);
1221 gtk_text_buffer_get_iter_at_offset( m_buffer
, &toi
, to
);
1223 gtk_text_buffer_delete( m_buffer
, &fromi
, &toi
);
1226 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1229 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
1231 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1237 SetInsertionPoint( from
);
1242 void wxTextCtrl::Cut()
1244 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1246 if (m_windowStyle
& wxTE_MULTILINE
)
1247 g_signal_emit_by_name (m_text
, "cut-clipboard");
1249 gtk_editable_cut_clipboard(GTK_EDITABLE(m_text
));
1252 void wxTextCtrl::Copy()
1254 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1256 if (m_windowStyle
& wxTE_MULTILINE
)
1257 g_signal_emit_by_name (m_text
, "copy-clipboard");
1259 gtk_editable_copy_clipboard(GTK_EDITABLE(m_text
));
1262 void wxTextCtrl::Paste()
1264 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1266 if (m_windowStyle
& wxTE_MULTILINE
)
1267 g_signal_emit_by_name (m_text
, "paste-clipboard");
1269 gtk_editable_paste_clipboard(GTK_EDITABLE(m_text
));
1273 void wxTextCtrl::Undo()
1276 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
1279 void wxTextCtrl::Redo()
1282 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
1285 bool wxTextCtrl::CanUndo() const
1288 //wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
1292 bool wxTextCtrl::CanRedo() const
1295 //wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
1299 // If the return values from and to are the same, there is no
1301 void wxTextCtrl::GetSelection(long* fromOut
, long* toOut
) const
1303 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1307 bool haveSelection
= false;
1309 if (m_windowStyle
& wxTE_MULTILINE
)
1311 GtkTextIter ifrom
, ito
;
1312 if ( gtk_text_buffer_get_selection_bounds(m_buffer
, &ifrom
, &ito
) )
1314 haveSelection
= true;
1315 from
= gtk_text_iter_get_offset(&ifrom
);
1316 to
= gtk_text_iter_get_offset(&ito
);
1319 else // not multi-line
1321 if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text
),
1324 haveSelection
= true;
1328 if (! haveSelection
)
1329 from
= to
= GetInsertionPoint();
1333 // exchange them to be compatible with wxMSW
1346 bool wxTextCtrl::IsEditable() const
1348 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1350 if (m_windowStyle
& wxTE_MULTILINE
)
1352 return gtk_text_view_get_editable(GTK_TEXT_VIEW(m_text
));
1356 return gtk_editable_get_editable(GTK_EDITABLE(m_text
));
1360 bool wxTextCtrl::IsModified() const
1365 void wxTextCtrl::Clear()
1367 SetValue( wxEmptyString
);
1370 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
1372 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1374 if ((key_event
.GetKeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
1376 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1377 event
.SetEventObject(this);
1378 event
.SetString(GetValue());
1379 if (GetEventHandler()->ProcessEvent(event
)) return;
1382 if ((key_event
.GetKeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
1384 // This will invoke the dialog default action, such
1385 // as the clicking the default button.
1387 wxWindow
*top_frame
= m_parent
;
1388 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
1389 top_frame
= top_frame
->GetParent();
1391 if (top_frame
&& GTK_IS_WINDOW(top_frame
->m_widget
))
1393 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
1395 if (window
->default_widget
)
1397 gtk_widget_activate (window
->default_widget
);
1406 GtkWidget
* wxTextCtrl::GetConnectWidget()
1408 return GTK_WIDGET(m_text
);
1411 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
1413 if (m_windowStyle
& wxTE_MULTILINE
)
1415 return window
== gtk_text_view_get_window( GTK_TEXT_VIEW( m_text
), GTK_TEXT_WINDOW_TEXT
); // pure guesswork
1419 return (window
== GTK_ENTRY(m_text
)->text_area
);
1423 // the font will change for subsequent text insertiongs
1424 bool wxTextCtrl::SetFont( const wxFont
&font
)
1426 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1428 if ( !wxTextCtrlBase::SetFont(font
) )
1430 // font didn't change, nothing to do
1434 if ( m_windowStyle
& wxTE_MULTILINE
)
1436 SetUpdateFont(true);
1438 m_defaultStyle
.SetFont(font
);
1440 ChangeFontGlobally();
1446 void wxTextCtrl::ChangeFontGlobally()
1448 // this method is very inefficient and hence should be called as rarely as
1451 // TODO: it can be implemented much more efficiently for GTK2
1452 wxASSERT_MSG( (m_windowStyle
& wxTE_MULTILINE
),
1453 _T("shouldn't be called for single line controls") );
1455 wxString value
= GetValue();
1456 if ( !value
.empty() )
1458 SetUpdateFont(false);
1465 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
1467 if ( !wxControl::SetForegroundColour(colour
) )
1470 // update default fg colour too
1471 m_defaultStyle
.SetTextColour(colour
);
1476 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
1478 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1480 if ( !wxControl::SetBackgroundColour( colour
) )
1483 if (!m_backgroundColour
.Ok())
1486 // change active background color too
1487 m_defaultStyle
.SetBackgroundColour( colour
);
1492 bool wxTextCtrl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1494 if ( m_windowStyle
& wxTE_MULTILINE
)
1496 if ( style
.IsDefault() )
1502 gint l
= gtk_text_buffer_get_char_count( m_buffer
);
1504 wxCHECK_MSG( start
>= 0 && end
<= l
, false,
1505 _T("invalid range in wxTextCtrl::SetStyle") );
1507 GtkTextIter starti
, endi
;
1508 gtk_text_buffer_get_iter_at_offset( m_buffer
, &starti
, start
);
1509 gtk_text_buffer_get_iter_at_offset( m_buffer
, &endi
, end
);
1511 // use the attributes from style which are set in it and fall back
1512 // first to the default style and then to the text control default
1513 // colours for the others
1514 wxTextAttr attr
= wxTextAttr::Combine(style
, m_defaultStyle
, this);
1516 wxGtkTextApplyTagsFromAttr( m_buffer
, attr
, &starti
, &endi
);
1522 // cannot do this for GTK+'s Entry widget
1526 void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
1528 gtk_widget_modify_style(m_text
, style
);
1531 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1536 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1541 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1546 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1551 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1556 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1558 event
.Enable( CanCut() );
1561 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1563 event
.Enable( CanCopy() );
1566 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1568 event
.Enable( CanPaste() );
1571 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1573 event
.Enable( CanUndo() );
1576 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1578 event
.Enable( CanRedo() );
1581 void wxTextCtrl::OnInternalIdle()
1583 wxCursor cursor
= m_cursor
;
1584 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1586 if (g_delayedFocus
== this)
1588 if (GTK_WIDGET_REALIZED(m_widget
))
1590 gtk_widget_grab_focus( m_widget
);
1591 g_delayedFocus
= NULL
;
1595 if (wxUpdateUIEvent::CanUpdate(this))
1596 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1599 wxSize
wxTextCtrl::DoGetBestSize() const
1601 // FIXME should be different for multi-line controls...
1602 wxSize
ret( wxControl::DoGetBestSize() );
1603 wxSize
best(80, ret
.y
);
1604 CacheBestSize(best
);
1608 // ----------------------------------------------------------------------------
1610 // ----------------------------------------------------------------------------
1612 void wxTextCtrl::Freeze()
1614 if ( HasFlag(wxTE_MULTILINE
) )
1616 if ( !m_frozenness
++ )
1618 // freeze textview updates and remove buffer
1619 g_signal_connect (m_text
, "expose_event",
1620 G_CALLBACK (gtk_text_exposed_callback
), this);
1621 g_signal_connect (m_widget
, "expose_event",
1622 G_CALLBACK (gtk_text_exposed_callback
), this);
1623 gtk_widget_set_sensitive(m_widget
, false);
1624 g_object_ref(m_buffer
);
1625 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text
), gtk_text_buffer_new(NULL
));
1630 void wxTextCtrl::Thaw()
1632 if ( HasFlag(wxTE_MULTILINE
) )
1634 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1636 if ( !--m_frozenness
)
1638 // Reattach buffer and thaw textview updates
1639 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text
), m_buffer
);
1640 g_object_unref(m_buffer
);
1641 gtk_widget_set_sensitive(m_widget
, true);
1642 g_signal_handlers_disconnect_by_func (m_widget
,
1643 (gpointer
) gtk_text_exposed_callback
, this);
1644 g_signal_handlers_disconnect_by_func (m_text
,
1645 (gpointer
) gtk_text_exposed_callback
, this);
1650 // ----------------------------------------------------------------------------
1651 // wxTextUrlEvent passing if style & wxTE_AUTO_URL
1652 // ----------------------------------------------------------------------------
1654 // FIXME: when dragging on a link the sample gets an "Unknown event".
1655 // This might be an excessive event from us or a buggy wxMouseEvent::Moving() or
1656 // a buggy sample, or something else
1657 void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent
& event
)
1660 if(!(m_windowStyle
& wxTE_AUTO_URL
))
1664 GtkTextIter start
, end
;
1665 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(m_buffer
),
1668 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(m_text
), GTK_TEXT_WINDOW_WIDGET
,
1669 event
.GetX(), event
.GetY(), &x
, &y
);
1671 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &end
, x
, y
);
1672 if (!gtk_text_iter_has_tag(&end
, tag
))
1674 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text
),
1675 GTK_TEXT_WINDOW_TEXT
), m_gdkXTermCursor
);
1679 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text
),
1680 GTK_TEXT_WINDOW_TEXT
), m_gdkHandCursor
);
1683 if(!gtk_text_iter_begins_tag(&start
, tag
))
1684 gtk_text_iter_backward_to_tag_toggle(&start
, tag
);
1685 if(!gtk_text_iter_ends_tag(&end
, tag
))
1686 gtk_text_iter_forward_to_tag_toggle(&end
, tag
);
1688 // Native context menu is probably not desired on an URL.
1689 // Consider making this dependant on ProcessEvent(wxTextUrlEvent) return value
1690 if(event
.GetEventType() == wxEVT_RIGHT_DOWN
)
1693 wxTextUrlEvent
url_event(m_windowId
, event
,
1694 gtk_text_iter_get_offset(&start
),
1695 gtk_text_iter_get_offset(&end
));
1697 InitCommandEvent(url_event
);
1698 // Is that a good idea? Seems not (pleasure with gtk_text_view_start_selection_drag)
1699 //event.Skip(!GetEventHandler()->ProcessEvent(url_event));
1700 GetEventHandler()->ProcessEvent(url_event
);
1705 wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1707 return GetDefaultAttributesFromGTKWidget(gtk_entry_new
, true);