1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/textctrl.cpp
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"
23 #include "wx/settings.h"
24 #include "wx/strconv.h"
25 #include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
27 #include <sys/types.h>
32 #include "wx/gtk/private.h"
33 #include <gdk/gdkkeysyms.h>
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 extern wxWindowGTK
*g_delayedFocus
;
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
46 static void wxGtkOnRemoveTag(GtkTextBuffer
*buffer
,
53 g_object_get (tag
, "name", &name
, NULL
);
55 if (!name
|| strncmp(name
, prefix
, strlen(prefix
)))
56 // anonymous tag or not starting with prefix - don't remove
57 g_signal_stop_emission_by_name (buffer
, "remove_tag");
64 static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer
*text_buffer
,
65 const wxTextAttr
& attr
,
69 static gchar buf
[1024];
72 gulong remove_handler_id
= g_signal_connect (text_buffer
, "remove_tag",
73 G_CALLBACK (wxGtkOnRemoveTag
), gpointer("WX"));
74 gtk_text_buffer_remove_all_tags(text_buffer
, start
, end
);
75 g_signal_handler_disconnect (text_buffer
, remove_handler_id
);
80 PangoFontDescription
*font_description
= attr
.GetFont().GetNativeFontInfo()->description
;
81 font_string
= pango_font_description_to_string(font_description
);
82 g_snprintf(buf
, sizeof(buf
), "WXFONT %s", font_string
);
83 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
86 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
87 "font-desc", font_description
,
89 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
92 if (attr
.GetFont().GetUnderlined())
94 g_snprintf(buf
, sizeof(buf
), "WXFONTUNDERLINE");
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 "underline-set", TRUE
,
100 "underline", PANGO_UNDERLINE_SINGLE
,
102 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
106 if (attr
.HasTextColour())
108 GdkColor
*colFg
= attr
.GetTextColour().GetColor();
109 g_snprintf(buf
, sizeof(buf
), "WXFORECOLOR %d %d %d",
110 colFg
->red
, colFg
->green
, colFg
->blue
);
111 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
114 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
115 "foreground-gdk", colFg
, NULL
);
116 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
119 if (attr
.HasBackgroundColour())
121 GdkColor
*colBg
= attr
.GetBackgroundColour().GetColor();
122 g_snprintf(buf
, sizeof(buf
), "WXBACKCOLOR %d %d %d",
123 colBg
->red
, colBg
->green
, colBg
->blue
);
124 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
127 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
128 "background-gdk", colBg
, NULL
);
129 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
132 if (attr
.HasAlignment())
134 GtkTextIter para_start
, para_end
= *end
;
135 gtk_text_buffer_get_iter_at_line( text_buffer
,
137 gtk_text_iter_get_line(start
) );
138 gtk_text_iter_forward_line(¶_end
);
140 remove_handler_id
= g_signal_connect (text_buffer
, "remove_tag",
141 G_CALLBACK(wxGtkOnRemoveTag
),
142 gpointer("WXALIGNMENT"));
143 gtk_text_buffer_remove_all_tags( text_buffer
, ¶_start
, ¶_end
);
144 g_signal_handler_disconnect (text_buffer
, remove_handler_id
);
146 GtkJustification align
;
147 switch (attr
.GetAlignment())
150 align
= GTK_JUSTIFY_LEFT
;
152 case wxTEXT_ALIGNMENT_RIGHT
:
153 align
= GTK_JUSTIFY_RIGHT
;
155 case wxTEXT_ALIGNMENT_CENTER
:
156 align
= GTK_JUSTIFY_CENTER
;
158 // gtk+ doesn't support justify as of gtk+-2.7.4
161 g_snprintf(buf
, sizeof(buf
), "WXALIGNMENT %d", align
);
162 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
165 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
166 "justification", align
, NULL
);
167 gtk_text_buffer_apply_tag( text_buffer
, tag
, ¶_start
, ¶_end
);
173 static void wxGtkTextInsert(GtkWidget
*text
,
174 GtkTextBuffer
*text_buffer
,
175 const wxTextAttr
& attr
,
176 const wxCharBuffer
& buffer
)
180 GtkTextIter iter
, start
;
182 gtk_text_buffer_get_iter_at_mark( text_buffer
, &iter
,
183 gtk_text_buffer_get_insert (text_buffer
) );
184 start_offset
= gtk_text_iter_get_offset (&iter
);
185 gtk_text_buffer_insert( text_buffer
, &iter
, buffer
, strlen(buffer
) );
187 gtk_text_buffer_get_iter_at_offset (text_buffer
, &start
, start_offset
);
189 wxGtkTextApplyTagsFromAttr(text_buffer
, attr
, &start
, &iter
);
193 // ----------------------------------------------------------------------------
194 // "insert_text" for GtkEntry
195 // ----------------------------------------------------------------------------
199 gtk_insert_text_callback(GtkEditable
*editable
,
200 const gchar
*new_text
,
201 gint new_text_length
,
206 wxapp_install_idle_handler();
208 // we should only be called if we have a max len limit at all
209 GtkEntry
*entry
= GTK_ENTRY (editable
);
211 wxCHECK_RET( entry
->text_max_length
, _T("shouldn't be called") );
213 // check that we don't overflow the max length limit
215 // FIXME: this doesn't work when we paste a string which is going to be
217 if ( entry
->text_length
== entry
->text_max_length
)
219 // we don't need to run the base class version at all
220 g_signal_stop_emission_by_name (editable
, "insert_text");
222 // remember that the next changed signal is to be ignored to avoid
223 // generating a dummy wxEVT_COMMAND_TEXT_UPDATED event
224 win
->IgnoreNextTextUpdate();
226 // and generate the correct one ourselves
227 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, win
->GetId());
228 event
.SetEventObject(win
);
229 event
.SetString(win
->GetValue());
230 win
->GetEventHandler()->ProcessEvent( event
);
235 // Implementation of wxTE_AUTO_URL for wxGTK2 by Mart Raudsepp,
239 au_apply_tag_callback(GtkTextBuffer
*buffer
,
245 if(tag
== gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl"))
246 g_signal_stop_emission_by_name (buffer
, "apply_tag");
250 //-----------------------------------------------------------------------------
251 // GtkTextCharPredicates for gtk_text_iter_*_find_char
252 //-----------------------------------------------------------------------------
256 pred_whitespace (gunichar ch
, gpointer user_data
)
258 return g_unichar_isspace(ch
);
264 pred_non_whitespace (gunichar ch
, gpointer user_data
)
266 return !g_unichar_isspace(ch
);
272 pred_nonpunct (gunichar ch
, gpointer user_data
)
274 return !g_unichar_ispunct(ch
);
280 pred_nonpunct_or_slash (gunichar ch
, gpointer user_data
)
282 return !g_unichar_ispunct(ch
) || ch
== '/';
286 //-----------------------------------------------------------------------------
287 // Check for links between s and e and correct tags as necessary
288 //-----------------------------------------------------------------------------
290 // This function should be made match better while being efficient at one point.
291 // Most probably with a row of regular expressions.
294 au_check_word( GtkTextIter
*s
, GtkTextIter
*e
)
296 static const char *URIPrefixes
[] =
314 GtkTextIter start
= *s
, end
= *e
;
315 GtkTextBuffer
*buffer
= gtk_text_iter_get_buffer(s
);
317 // Get our special link tag
318 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl");
320 // Get rid of punctuation from beginning and end.
321 // Might want to move this to au_check_range if an improved link checking doesn't
322 // use some intelligent punctuation checking itself (beware of undesired iter modifications).
323 if(g_unichar_ispunct( gtk_text_iter_get_char( &start
) ) )
324 gtk_text_iter_forward_find_char( &start
, pred_nonpunct
, NULL
, e
);
326 gtk_text_iter_backward_find_char( &end
, pred_nonpunct_or_slash
, NULL
, &start
);
327 gtk_text_iter_forward_char(&end
);
329 gchar
* text
= gtk_text_iter_get_text( &start
, &end
);
330 size_t len
= strlen(text
), prefix_len
;
333 for( n
= 0; n
< WXSIZEOF(URIPrefixes
); ++n
)
335 prefix_len
= strlen(URIPrefixes
[n
]);
336 if((len
> prefix_len
) && !strncasecmp(text
, URIPrefixes
[n
], prefix_len
))
340 if(n
< WXSIZEOF(URIPrefixes
))
342 gulong signal_id
= g_signal_handler_find (buffer
,
343 (GSignalMatchType
) (G_SIGNAL_MATCH_FUNC
),
345 (gpointer
)au_apply_tag_callback
, NULL
);
347 g_signal_handler_block (buffer
, signal_id
);
348 gtk_text_buffer_apply_tag(buffer
, tag
, &start
, &end
);
349 g_signal_handler_unblock (buffer
, signal_id
);
356 au_check_range(GtkTextIter
*s
,
357 GtkTextIter
*range_end
)
359 GtkTextIter range_start
= *s
;
360 GtkTextIter word_end
;
361 GtkTextBuffer
*buffer
= gtk_text_iter_get_buffer(s
);
362 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl");
364 gtk_text_buffer_remove_tag(buffer
, tag
, s
, range_end
);
366 if(g_unichar_isspace(gtk_text_iter_get_char(&range_start
)))
367 gtk_text_iter_forward_find_char(&range_start
, pred_non_whitespace
, NULL
, range_end
);
369 while(!gtk_text_iter_equal(&range_start
, range_end
))
371 word_end
= range_start
;
372 gtk_text_iter_forward_find_char(&word_end
, pred_whitespace
, NULL
, range_end
);
374 // Now we should have a word delimited by range_start and word_end, correct link tags
375 au_check_word(&range_start
, &word_end
);
377 range_start
= word_end
;
378 gtk_text_iter_forward_find_char(&range_start
, pred_non_whitespace
, NULL
, range_end
);
383 //-----------------------------------------------------------------------------
384 // "insert-text" for GtkTextBuffer
385 //-----------------------------------------------------------------------------
389 au_insert_text_callback(GtkTextBuffer
*buffer
,
395 if (!len
|| !(win
->GetWindowStyleFlag() & wxTE_AUTO_URL
) )
398 GtkTextIter start
= *end
;
399 gtk_text_iter_backward_chars(&start
, g_utf8_strlen(text
, len
));
401 GtkTextIter line_start
= start
;
402 GtkTextIter line_end
= *end
;
403 GtkTextIter words_start
= start
;
404 GtkTextIter words_end
= *end
;
406 gtk_text_iter_set_line(&line_start
, gtk_text_iter_get_line(&start
));
407 gtk_text_iter_forward_to_line_end(&line_end
);
408 gtk_text_iter_backward_find_char(&words_start
, pred_whitespace
, NULL
, &line_start
);
409 gtk_text_iter_forward_find_char(&words_end
, pred_whitespace
, NULL
, &line_end
);
411 au_check_range(&words_start
, &words_end
);
415 //-----------------------------------------------------------------------------
416 // "delete-range" for GtkTextBuffer
417 //-----------------------------------------------------------------------------
421 au_delete_range_callback(GtkTextBuffer
*buffer
,
426 if( !(win
->GetWindowStyleFlag() & wxTE_AUTO_URL
) )
429 GtkTextIter line_start
= *start
, line_end
= *end
;
431 gtk_text_iter_set_line(&line_start
, gtk_text_iter_get_line(start
));
432 gtk_text_iter_forward_to_line_end(&line_end
);
433 gtk_text_iter_backward_find_char(start
, pred_whitespace
, NULL
, &line_start
);
434 gtk_text_iter_forward_find_char(end
, pred_whitespace
, NULL
, &line_end
);
436 au_check_range(start
, end
);
441 //-----------------------------------------------------------------------------
443 //-----------------------------------------------------------------------------
447 gtk_text_changed_callback( GtkWidget
*widget
, wxTextCtrl
*win
)
449 if ( win
->IgnoreTextUpdate() )
452 if (!win
->m_hasVMT
) return;
455 wxapp_install_idle_handler();
459 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->GetId() );
460 event
.SetEventObject( win
);
461 win
->GetEventHandler()->ProcessEvent( event
);
465 //-----------------------------------------------------------------------------
466 // "expose_event" from scrolled window and textview
467 //-----------------------------------------------------------------------------
471 gtk_text_exposed_callback( GtkWidget
*widget
, GdkEventExpose
*event
, wxTextCtrl
*win
)
478 //-----------------------------------------------------------------------------
480 //-----------------------------------------------------------------------------
482 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
484 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
485 EVT_CHAR(wxTextCtrl::OnChar
)
487 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
488 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
489 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
490 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
491 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
493 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
494 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
495 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
496 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
497 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
499 // wxTE_AUTO_URL wxTextUrl support. Currently only creates
500 // wxTextUrlEvent in the same cases as wxMSW, more can be added here.
501 EVT_MOTION (wxTextCtrl::OnUrlMouseEvent
)
502 EVT_LEFT_DOWN (wxTextCtrl::OnUrlMouseEvent
)
503 EVT_LEFT_UP (wxTextCtrl::OnUrlMouseEvent
)
504 EVT_LEFT_DCLICK (wxTextCtrl::OnUrlMouseEvent
)
505 EVT_RIGHT_DOWN (wxTextCtrl::OnUrlMouseEvent
)
506 EVT_RIGHT_UP (wxTextCtrl::OnUrlMouseEvent
)
507 EVT_RIGHT_DCLICK(wxTextCtrl::OnUrlMouseEvent
)
510 void wxTextCtrl::Init()
514 SetUpdateFont(false);
517 m_gdkHandCursor
= NULL
;
518 m_gdkXTermCursor
= NULL
;
521 wxTextCtrl::~wxTextCtrl()
524 gdk_cursor_unref(m_gdkHandCursor
);
526 gdk_cursor_unref(m_gdkXTermCursor
);
529 wxTextCtrl::wxTextCtrl( wxWindow
*parent
,
531 const wxString
&value
,
535 const wxValidator
& validator
,
536 const wxString
&name
)
540 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
543 bool wxTextCtrl::Create( wxWindow
*parent
,
545 const wxString
&value
,
549 const wxValidator
& validator
,
550 const wxString
&name
)
553 m_acceptsFocus
= true;
555 if (!PreCreation( parent
, pos
, size
) ||
556 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
558 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
562 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
567 m_text
= gtk_text_view_new();
569 m_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
571 // create scrolled window
572 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
573 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget
),
574 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
576 // Insert view into scrolled window
577 gtk_container_add( GTK_CONTAINER(m_widget
), m_text
);
579 // translate wx wrapping style to GTK+
581 if ( HasFlag( wxTE_DONTWRAP
) )
582 wrap
= GTK_WRAP_NONE
;
583 else if ( HasFlag( wxTE_CHARWRAP
) )
584 wrap
= GTK_WRAP_CHAR
;
585 else if ( HasFlag( wxTE_WORDWRAP
) )
586 wrap
= GTK_WRAP_WORD
;
587 else // HasFlag(wxTE_BESTWRAP) always true as wxTE_BESTWRAP == 0
589 // GTK_WRAP_WORD_CHAR seems to be new in GTK+ 2.4
591 if ( !gtk_check_version(2,4,0) )
593 wrap
= GTK_WRAP_WORD_CHAR
;
597 wrap
= GTK_WRAP_WORD
;
600 gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text
), wrap
);
602 GtkScrolledWindowSetBorder(m_widget
, style
);
604 gtk_widget_add_events( GTK_WIDGET(m_text
), GDK_ENTER_NOTIFY_MASK
| GDK_LEAVE_NOTIFY_MASK
);
606 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
610 // a single-line text control: no need for scrollbars
612 m_text
= gtk_entry_new();
614 if (style
& wxNO_BORDER
)
615 g_object_set (m_text
, "has-frame", FALSE
, NULL
);
618 m_parent
->DoAddChild( this );
620 m_focusWidget
= m_text
;
626 gtk_widget_show(m_text
);
627 SetVScrollAdjustment(gtk_scrolled_window_get_vadjustment((GtkScrolledWindow
*)m_widget
));
635 if (style
& wxTE_PASSWORD
)
638 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
641 if (style
& wxTE_READONLY
)
644 gtk_editable_set_editable( GTK_EDITABLE(m_text
), FALSE
);
646 gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text
), FALSE
);
651 if (style
& wxTE_RIGHT
)
652 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_RIGHT
);
653 else if (style
& wxTE_CENTRE
)
654 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_CENTER
);
655 // Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
660 // gtk_entry_set_alignment was introduced in gtk+-2.3.5
661 if (!gtk_check_version(2,4,0))
663 if (style
& wxTE_RIGHT
)
664 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 1.0 );
665 else if (style
& wxTE_CENTRE
)
666 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 0.5 );
671 // We want to be notified about text changes.
674 g_signal_connect (m_buffer
, "changed",
675 G_CALLBACK (gtk_text_changed_callback
), this);
677 // .. and handle URLs on multi-line controls with wxTE_AUTO_URL style
678 if (style
& wxTE_AUTO_URL
)
680 GtkTextIter start
, end
;
681 m_gdkHandCursor
= gdk_cursor_new(GDK_HAND2
);
682 m_gdkXTermCursor
= gdk_cursor_new(GDK_XTERM
);
684 // We create our wxUrl tag here for slight efficiency gain - we
685 // don't have to check for the tag existance in callbacks,
686 // hereby it's guaranteed to exist.
687 gtk_text_buffer_create_tag(m_buffer
, "wxUrl",
688 "foreground", "blue",
689 "underline", PANGO_UNDERLINE_SINGLE
,
692 // Check for URLs after each text change
693 g_signal_connect_after (m_buffer
, "insert_text",
694 G_CALLBACK (au_insert_text_callback
), this);
695 g_signal_connect_after (m_buffer
, "delete_range",
696 G_CALLBACK (au_delete_range_callback
), this);
698 // Block all wxUrl tag applying unless we do it ourselves, in which case we
699 // block this callback temporarily. This takes care of gtk+ internal
700 // gtk_text_buffer_insert_range* calls that would copy our URL tag otherwise,
701 // which is undesired because only a part of the URL might be copied.
702 // The insert-text signal emitted inside it will take care of newly formed
703 // or wholly copied URLs.
704 g_signal_connect (m_buffer
, "apply_tag",
705 G_CALLBACK (au_apply_tag_callback
), NULL
);
707 // Check for URLs in the initial string passed to Create
708 gtk_text_buffer_get_start_iter(m_buffer
, &start
);
709 gtk_text_buffer_get_end_iter(m_buffer
, &end
);
710 au_check_range(&start
, &end
);
715 g_signal_connect (m_text
, "changed",
716 G_CALLBACK (gtk_text_changed_callback
), this);
719 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
721 wxTextAttr
attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont());
722 SetDefaultStyle( attrDef
);
728 void wxTextCtrl::CalculateScrollbar()
732 wxString
wxTextCtrl::GetValue() const
734 wxCHECK_MSG( m_text
!= NULL
, wxEmptyString
, wxT("invalid text ctrl") );
737 if (m_windowStyle
& wxTE_MULTILINE
)
740 gtk_text_buffer_get_start_iter( m_buffer
, &start
);
742 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
743 gchar
*text
= gtk_text_buffer_get_text( m_buffer
, &start
, &end
, TRUE
);
745 const wxWxCharBuffer buf
= wxGTK_CONV_BACK(text
);
753 const gchar
*text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
754 const wxWxCharBuffer buf
= wxGTK_CONV_BACK( text
);
762 void wxTextCtrl::SetValue( const wxString
&value
)
764 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
766 if (m_windowStyle
& wxTE_MULTILINE
)
768 const wxCharBuffer
buffer(wxGTK_CONV(value
));
771 // what else can we do? at least don't crash...
775 if (gtk_text_buffer_get_char_count(m_buffer
) != 0)
776 IgnoreNextTextUpdate();
778 gtk_text_buffer_set_text( m_buffer
, buffer
, strlen(buffer
) );
782 // gtk_entry_set_text() emits two "changed" signals because internally
783 // it calls gtk_editable_delete_text() and gtk_editable_insert_text()
784 // but we want to have only one event
785 IgnoreNextTextUpdate();
787 gtk_entry_set_text( GTK_ENTRY(m_text
), wxGTK_CONV(value
) );
790 // GRG, Jun/2000: Changed this after a lot of discussion in
791 // the lists. wxWidgets 2.2 will have a set of flags to
792 // customize this behaviour.
793 SetInsertionPoint(0);
798 void wxTextCtrl::WriteText( const wxString
&text
)
800 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
805 const wxCharBuffer
buffer(wxGTK_CONV(text
));
808 // what else can we do? at least don't crash...
812 // gtk_text_changed_callback() will set m_modified to true but m_modified
813 // shouldn't be changed by the program writing to the text control itself,
814 // so save the old value and restore when we're done
815 bool oldModified
= m_modified
;
817 if ( m_windowStyle
& wxTE_MULTILINE
)
819 // First remove the selection if there is one
820 // TODO: Is there an easier GTK specific way to do this?
822 GetSelection(&from
, &to
);
827 wxGtkTextInsert( m_text
, m_buffer
, m_defaultStyle
, buffer
);
829 GtkAdjustment
*adj
= gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(m_widget
) );
830 // Scroll to cursor, but only if scrollbar thumb is at the very bottom
831 if ( wxIsSameDouble(adj
->value
, adj
->upper
- adj
->page_size
) )
833 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
),
834 gtk_text_buffer_get_insert( m_buffer
), 0.0, FALSE
, 0.0, 1.0 );
839 // First remove the selection if there is one
840 gtk_editable_delete_selection( GTK_EDITABLE(m_text
) );
842 // This moves the cursor pos to behind the inserted text.
843 gint len
= gtk_editable_get_position(GTK_EDITABLE(m_text
));
845 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buffer
, strlen(buffer
), &len
);
847 // Bring entry's cursor uptodate.
848 gtk_editable_set_position( GTK_EDITABLE(m_text
), len
);
851 m_modified
= oldModified
;
854 void wxTextCtrl::AppendText( const wxString
&text
)
856 SetInsertionPointEnd();
860 wxString
wxTextCtrl::GetLineText( long lineNo
) const
862 if (m_windowStyle
& wxTE_MULTILINE
)
865 gtk_text_buffer_get_iter_at_line(m_buffer
,&line
,lineNo
);
866 GtkTextIter end
= line
;
867 gtk_text_iter_forward_to_line_end(&end
);
868 gchar
*text
= gtk_text_buffer_get_text(m_buffer
,&line
,&end
,TRUE
);
869 wxString
result(wxGTK_CONV_BACK(text
));
875 if (lineNo
== 0) return GetValue();
876 return wxEmptyString
;
880 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
882 /* If you implement this, don't forget to update the documentation!
883 * (file docs/latex/wx/text.tex) */
884 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
887 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
889 if ( m_windowStyle
& wxTE_MULTILINE
)
892 gtk_text_buffer_get_iter_at_offset(m_buffer
, &iter
, pos
);
893 if (gtk_text_iter_is_end(&iter
))
896 *y
= gtk_text_iter_get_line(&iter
);
897 *x
= gtk_text_iter_get_line_offset(&iter
);
899 else // single line control
901 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
908 // index out of bounds
916 long wxTextCtrl::XYToPosition(long x
, long y
) const
918 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
921 if (y
>= gtk_text_buffer_get_line_count (m_buffer
))
924 gtk_text_buffer_get_iter_at_line(m_buffer
, &iter
, y
);
925 if (x
>= gtk_text_iter_get_chars_in_line (&iter
))
928 return gtk_text_iter_get_offset(&iter
) + x
;
931 int wxTextCtrl::GetLineLength(long lineNo
) const
933 if (m_windowStyle
& wxTE_MULTILINE
)
935 int last_line
= gtk_text_buffer_get_line_count( m_buffer
) - 1;
936 if (lineNo
> last_line
)
940 gtk_text_buffer_get_iter_at_line(m_buffer
, &iter
, lineNo
);
941 // get_chars_in_line return includes paragraph delimiters, so need to subtract 1 IF it is not the last line
942 return gtk_text_iter_get_chars_in_line(&iter
) - ((lineNo
== last_line
) ? 0 : 1);
946 wxString str
= GetLineText (lineNo
);
947 return (int) str
.length();
951 int wxTextCtrl::GetNumberOfLines() const
953 if ( m_windowStyle
& wxTE_MULTILINE
)
956 gtk_text_buffer_get_iter_at_offset( m_buffer
, &iter
, 0 );
958 // move forward by one display line until the end is reached
960 while ( gtk_text_view_forward_display_line(GTK_TEXT_VIEW(m_text
), &iter
) )
965 // If the last character in the text buffer is a newline,
966 // gtk_text_view_forward_display_line() will return false without that
967 // line being counted. Must add one manually in that case.
968 GtkTextIter lastCharIter
;
969 gtk_text_buffer_get_iter_at_offset
973 gtk_text_buffer_get_char_count(m_buffer
) - 1
975 gchar lastChar
= gtk_text_iter_get_char( &lastCharIter
);
976 if ( lastChar
== wxT('\n') )
987 void wxTextCtrl::SetInsertionPoint( long pos
)
989 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
994 gtk_text_buffer_get_iter_at_offset( m_buffer
, &iter
, pos
);
995 gtk_text_buffer_place_cursor( m_buffer
, &iter
);
996 gtk_text_view_scroll_mark_onscreen
998 GTK_TEXT_VIEW(m_text
),
999 gtk_text_buffer_get_insert( m_buffer
)
1004 // FIXME: Is the editable's cursor really uptodate without double set_position in GTK2?
1005 gtk_editable_set_position(GTK_EDITABLE(m_text
), int(pos
));
1009 void wxTextCtrl::SetInsertionPointEnd()
1011 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1013 if (m_windowStyle
& wxTE_MULTILINE
)
1016 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
1017 gtk_text_buffer_place_cursor( m_buffer
, &end
);
1021 gtk_editable_set_position( GTK_EDITABLE(m_text
), -1 );
1025 void wxTextCtrl::SetEditable( bool editable
)
1027 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1029 if (m_windowStyle
& wxTE_MULTILINE
)
1031 gtk_text_view_set_editable( GTK_TEXT_VIEW(m_text
), editable
);
1035 gtk_editable_set_editable( GTK_EDITABLE(m_text
), editable
);
1039 bool wxTextCtrl::Enable( bool enable
)
1041 if (!wxWindowBase::Enable(enable
))
1047 if (m_windowStyle
& wxTE_MULTILINE
)
1049 SetEditable( enable
);
1053 gtk_widget_set_sensitive( m_text
, enable
);
1059 // wxGTK-specific: called recursively by Enable,
1060 // to give widgets an oppprtunity to correct their colours after they
1061 // have been changed by Enable
1062 void wxTextCtrl::OnParentEnable( bool enable
)
1064 // If we have a custom background colour, we use this colour in both
1065 // disabled and enabled mode, or we end up with a different colour under the
1067 wxColour oldColour
= GetBackgroundColour();
1070 // Need to set twice or it'll optimize the useful stuff out
1071 if (oldColour
== * wxWHITE
)
1072 SetBackgroundColour(*wxBLACK
);
1074 SetBackgroundColour(*wxWHITE
);
1075 SetBackgroundColour(oldColour
);
1079 void wxTextCtrl::MarkDirty()
1084 void wxTextCtrl::DiscardEdits()
1089 // ----------------------------------------------------------------------------
1090 // max text length support
1091 // ----------------------------------------------------------------------------
1093 void wxTextCtrl::IgnoreNextTextUpdate()
1095 m_ignoreNextUpdate
= true;
1098 bool wxTextCtrl::IgnoreTextUpdate()
1100 if ( m_ignoreNextUpdate
)
1102 m_ignoreNextUpdate
= false;
1110 void wxTextCtrl::SetMaxLength(unsigned long len
)
1112 if ( !HasFlag(wxTE_MULTILINE
) )
1114 gtk_entry_set_max_length(GTK_ENTRY(m_text
), len
);
1116 // there is a bug in GTK+ 1.2.x: "changed" signal is emitted even if
1117 // we had tried to enter more text than allowed by max text length and
1118 // the text wasn't really changed
1120 // to detect this and generate TEXT_MAXLEN event instead of
1121 // TEXT_CHANGED one in this case we also catch "insert_text" signal
1123 // when max len is set to 0 we disconnect our handler as it means that
1124 // we shouldn't check anything any more
1127 g_signal_connect (m_text
, "insert_text",
1128 G_CALLBACK (gtk_insert_text_callback
), this);
1132 g_signal_handlers_disconnect_by_func (m_text
,
1133 (gpointer
) gtk_insert_text_callback
, this);
1138 void wxTextCtrl::SetSelection( long from
, long to
)
1140 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1142 if (from
== -1 && to
== -1)
1145 to
= GetValue().length();
1148 if (m_windowStyle
& wxTE_MULTILINE
)
1150 GtkTextIter fromi
, toi
;
1151 gtk_text_buffer_get_iter_at_offset( m_buffer
, &fromi
, from
);
1152 gtk_text_buffer_get_iter_at_offset( m_buffer
, &toi
, to
);
1154 gtk_text_buffer_place_cursor( m_buffer
, &toi
);
1155 gtk_text_buffer_move_mark_by_name( m_buffer
, "selection_bound", &fromi
);
1159 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1163 void wxTextCtrl::ShowPosition( long pos
)
1165 if (m_windowStyle
& wxTE_MULTILINE
)
1168 gtk_text_buffer_get_start_iter( m_buffer
, &iter
);
1169 gtk_text_iter_set_offset( &iter
, pos
);
1170 GtkTextMark
*mark
= gtk_text_buffer_create_mark( m_buffer
, NULL
, &iter
, TRUE
);
1171 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
), mark
, 0.0, FALSE
, 0.0, 0.0 );
1175 wxTextCtrlHitTestResult
1176 wxTextCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
1178 if ( !IsMultiLine() )
1181 return wxTE_HT_UNKNOWN
;
1185 gtk_text_view_window_to_buffer_coords
1187 GTK_TEXT_VIEW(m_text
),
1188 GTK_TEXT_WINDOW_TEXT
,
1194 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &iter
, x
, y
);
1196 *pos
= gtk_text_iter_get_offset(&iter
);
1198 return wxTE_HT_ON_TEXT
;
1201 long wxTextCtrl::GetInsertionPoint() const
1203 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1205 if (m_windowStyle
& wxTE_MULTILINE
)
1207 // There is no direct accessor for the cursor, but
1208 // internally, the cursor is the "mark" called
1209 // "insert" in the text view's btree structure.
1211 GtkTextMark
*mark
= gtk_text_buffer_get_insert( m_buffer
);
1213 gtk_text_buffer_get_iter_at_mark( m_buffer
, &cursor
, mark
);
1215 return gtk_text_iter_get_offset( &cursor
);
1219 return (long) gtk_editable_get_position(GTK_EDITABLE(m_text
));
1223 wxTextPos
wxTextCtrl::GetLastPosition() const
1225 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1229 if (m_windowStyle
& wxTE_MULTILINE
)
1232 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
1234 pos
= gtk_text_iter_get_offset( &end
);
1238 pos
= GTK_ENTRY(m_text
)->text_length
;
1244 void wxTextCtrl::Remove( long from
, long to
)
1246 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1248 if (m_windowStyle
& wxTE_MULTILINE
)
1250 GtkTextIter fromi
, toi
;
1251 gtk_text_buffer_get_iter_at_offset( m_buffer
, &fromi
, from
);
1252 gtk_text_buffer_get_iter_at_offset( m_buffer
, &toi
, to
);
1254 gtk_text_buffer_delete( m_buffer
, &fromi
, &toi
);
1257 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1260 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
1262 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1268 SetInsertionPoint( from
);
1273 void wxTextCtrl::Cut()
1275 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1277 if (m_windowStyle
& wxTE_MULTILINE
)
1278 g_signal_emit_by_name (m_text
, "cut-clipboard");
1280 gtk_editable_cut_clipboard(GTK_EDITABLE(m_text
));
1283 void wxTextCtrl::Copy()
1285 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1287 if (m_windowStyle
& wxTE_MULTILINE
)
1288 g_signal_emit_by_name (m_text
, "copy-clipboard");
1290 gtk_editable_copy_clipboard(GTK_EDITABLE(m_text
));
1293 void wxTextCtrl::Paste()
1295 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1297 if (m_windowStyle
& wxTE_MULTILINE
)
1298 g_signal_emit_by_name (m_text
, "paste-clipboard");
1300 gtk_editable_paste_clipboard(GTK_EDITABLE(m_text
));
1304 void wxTextCtrl::Undo()
1307 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
1310 void wxTextCtrl::Redo()
1313 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
1316 bool wxTextCtrl::CanUndo() const
1319 //wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
1323 bool wxTextCtrl::CanRedo() const
1326 //wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
1330 // If the return values from and to are the same, there is no
1332 void wxTextCtrl::GetSelection(long* fromOut
, long* toOut
) const
1334 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1338 bool haveSelection
= false;
1340 if (m_windowStyle
& wxTE_MULTILINE
)
1342 GtkTextIter ifrom
, ito
;
1343 if ( gtk_text_buffer_get_selection_bounds(m_buffer
, &ifrom
, &ito
) )
1345 haveSelection
= true;
1346 from
= gtk_text_iter_get_offset(&ifrom
);
1347 to
= gtk_text_iter_get_offset(&ito
);
1350 else // not multi-line
1352 if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text
),
1355 haveSelection
= true;
1359 if (! haveSelection
)
1360 from
= to
= GetInsertionPoint();
1364 // exchange them to be compatible with wxMSW
1377 bool wxTextCtrl::IsEditable() const
1379 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1381 if (m_windowStyle
& wxTE_MULTILINE
)
1383 return gtk_text_view_get_editable(GTK_TEXT_VIEW(m_text
));
1387 return gtk_editable_get_editable(GTK_EDITABLE(m_text
));
1391 bool wxTextCtrl::IsModified() const
1396 void wxTextCtrl::Clear()
1398 SetValue( wxEmptyString
);
1401 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
1403 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1405 if ((key_event
.GetKeyCode() == WXK_RETURN
) && (m_windowStyle
& wxTE_PROCESS_ENTER
))
1407 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1408 event
.SetEventObject(this);
1409 event
.SetString(GetValue());
1410 if (GetEventHandler()->ProcessEvent(event
)) return;
1413 if ((key_event
.GetKeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
1415 // This will invoke the dialog default action, such
1416 // as the clicking the default button.
1418 wxWindow
*top_frame
= m_parent
;
1419 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
1420 top_frame
= top_frame
->GetParent();
1422 if (top_frame
&& GTK_IS_WINDOW(top_frame
->m_widget
))
1424 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
1426 if (window
->default_widget
)
1428 gtk_widget_activate (window
->default_widget
);
1437 GtkWidget
* wxTextCtrl::GetConnectWidget()
1439 return GTK_WIDGET(m_text
);
1442 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
1444 if (m_windowStyle
& wxTE_MULTILINE
)
1446 return window
== gtk_text_view_get_window( GTK_TEXT_VIEW( m_text
), GTK_TEXT_WINDOW_TEXT
); // pure guesswork
1450 return (window
== GTK_ENTRY(m_text
)->text_area
);
1454 // the font will change for subsequent text insertiongs
1455 bool wxTextCtrl::SetFont( const wxFont
&font
)
1457 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1459 if ( !wxTextCtrlBase::SetFont(font
) )
1461 // font didn't change, nothing to do
1465 if ( m_windowStyle
& wxTE_MULTILINE
)
1467 SetUpdateFont(true);
1469 m_defaultStyle
.SetFont(font
);
1471 ChangeFontGlobally();
1477 void wxTextCtrl::ChangeFontGlobally()
1479 // this method is very inefficient and hence should be called as rarely as
1482 // TODO: it can be implemented much more efficiently for GTK2
1483 wxASSERT_MSG( (m_windowStyle
& wxTE_MULTILINE
),
1484 _T("shouldn't be called for single line controls") );
1486 wxString value
= GetValue();
1487 if ( !value
.empty() )
1489 SetUpdateFont(false);
1496 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
1498 if ( !wxControl::SetForegroundColour(colour
) )
1501 // update default fg colour too
1502 m_defaultStyle
.SetTextColour(colour
);
1507 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
1509 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1511 if ( !wxControl::SetBackgroundColour( colour
) )
1514 if (!m_backgroundColour
.Ok())
1517 // change active background color too
1518 m_defaultStyle
.SetBackgroundColour( colour
);
1523 bool wxTextCtrl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1525 if ( m_windowStyle
& wxTE_MULTILINE
)
1527 if ( style
.IsDefault() )
1533 gint l
= gtk_text_buffer_get_char_count( m_buffer
);
1535 wxCHECK_MSG( start
>= 0 && end
<= l
, false,
1536 _T("invalid range in wxTextCtrl::SetStyle") );
1538 GtkTextIter starti
, endi
;
1539 gtk_text_buffer_get_iter_at_offset( m_buffer
, &starti
, start
);
1540 gtk_text_buffer_get_iter_at_offset( m_buffer
, &endi
, end
);
1542 // use the attributes from style which are set in it and fall back
1543 // first to the default style and then to the text control default
1544 // colours for the others
1545 wxTextAttr attr
= wxTextAttr::Combine(style
, m_defaultStyle
, this);
1547 wxGtkTextApplyTagsFromAttr( m_buffer
, attr
, &starti
, &endi
);
1553 // cannot do this for GTK+'s Entry widget
1557 void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
1559 gtk_widget_modify_style(m_text
, style
);
1562 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1567 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1572 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1577 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1582 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1587 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1589 event
.Enable( CanCut() );
1592 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1594 event
.Enable( CanCopy() );
1597 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1599 event
.Enable( CanPaste() );
1602 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1604 event
.Enable( CanUndo() );
1607 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1609 event
.Enable( CanRedo() );
1612 void wxTextCtrl::OnInternalIdle()
1614 if (g_delayedFocus
== this)
1616 if (GTK_WIDGET_REALIZED(m_widget
))
1618 gtk_widget_grab_focus( m_widget
);
1619 g_delayedFocus
= NULL
;
1623 if (wxUpdateUIEvent::CanUpdate(this))
1624 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1627 wxSize
wxTextCtrl::DoGetBestSize() const
1629 // FIXME should be different for multi-line controls...
1630 wxSize
ret( wxControl::DoGetBestSize() );
1631 wxSize
best(80, ret
.y
);
1632 CacheBestSize(best
);
1636 // ----------------------------------------------------------------------------
1638 // ----------------------------------------------------------------------------
1640 void wxTextCtrl::Freeze()
1642 if ( HasFlag(wxTE_MULTILINE
) )
1644 if ( !m_frozenness
++ )
1646 // freeze textview updates and remove buffer
1647 g_signal_connect (m_text
, "expose_event",
1648 G_CALLBACK (gtk_text_exposed_callback
), this);
1649 g_signal_connect (m_widget
, "expose_event",
1650 G_CALLBACK (gtk_text_exposed_callback
), this);
1651 gtk_widget_set_sensitive(m_widget
, false);
1652 g_object_ref(m_buffer
);
1653 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text
), gtk_text_buffer_new(NULL
));
1658 void wxTextCtrl::Thaw()
1660 if ( HasFlag(wxTE_MULTILINE
) )
1662 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1664 if ( !--m_frozenness
)
1666 // Reattach buffer and thaw textview updates
1667 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text
), m_buffer
);
1668 g_object_unref(m_buffer
);
1669 gtk_widget_set_sensitive(m_widget
, true);
1670 g_signal_handlers_disconnect_by_func (m_widget
,
1671 (gpointer
) gtk_text_exposed_callback
, this);
1672 g_signal_handlers_disconnect_by_func (m_text
,
1673 (gpointer
) gtk_text_exposed_callback
, this);
1678 // ----------------------------------------------------------------------------
1679 // wxTextUrlEvent passing if style & wxTE_AUTO_URL
1680 // ----------------------------------------------------------------------------
1682 // FIXME: when dragging on a link the sample gets an "Unknown event".
1683 // This might be an excessive event from us or a buggy wxMouseEvent::Moving() or
1684 // a buggy sample, or something else
1685 void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent
& event
)
1688 if(!(m_windowStyle
& wxTE_AUTO_URL
))
1692 GtkTextIter start
, end
;
1693 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(m_buffer
),
1696 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(m_text
), GTK_TEXT_WINDOW_WIDGET
,
1697 event
.GetX(), event
.GetY(), &x
, &y
);
1699 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &end
, x
, y
);
1700 if (!gtk_text_iter_has_tag(&end
, tag
))
1702 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text
),
1703 GTK_TEXT_WINDOW_TEXT
), m_gdkXTermCursor
);
1707 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text
),
1708 GTK_TEXT_WINDOW_TEXT
), m_gdkHandCursor
);
1711 if(!gtk_text_iter_begins_tag(&start
, tag
))
1712 gtk_text_iter_backward_to_tag_toggle(&start
, tag
);
1713 if(!gtk_text_iter_ends_tag(&end
, tag
))
1714 gtk_text_iter_forward_to_tag_toggle(&end
, tag
);
1716 // Native context menu is probably not desired on an URL.
1717 // Consider making this dependant on ProcessEvent(wxTextUrlEvent) return value
1718 if(event
.GetEventType() == wxEVT_RIGHT_DOWN
)
1721 wxTextUrlEvent
url_event(m_windowId
, event
,
1722 gtk_text_iter_get_offset(&start
),
1723 gtk_text_iter_get_offset(&end
));
1725 InitCommandEvent(url_event
);
1726 // Is that a good idea? Seems not (pleasure with gtk_text_view_start_selection_drag)
1727 //event.Skip(!GetEventHandler()->ProcessEvent(url_event));
1728 GetEventHandler()->ProcessEvent(url_event
);
1733 wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1735 return GetDefaultAttributesFromGTKWidget(gtk_entry_new
, true);