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 wxCursor g_globalCursor
;
40 extern wxWindowGTK
*g_delayedFocus
;
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
47 static void wxGtkOnRemoveTag(GtkTextBuffer
*buffer
,
54 g_object_get (tag
, "name", &name
, NULL
);
56 if (!name
|| strncmp(name
, prefix
, strlen(prefix
)))
57 // anonymous tag or not starting with prefix - don't remove
58 g_signal_stop_emission_by_name (buffer
, "remove_tag");
65 static void wxGtkTextApplyTagsFromAttr(GtkTextBuffer
*text_buffer
,
66 const wxTextAttr
& attr
,
70 static gchar buf
[1024];
73 gulong remove_handler_id
= g_signal_connect (text_buffer
, "remove_tag",
74 G_CALLBACK (wxGtkOnRemoveTag
), gpointer("WX"));
75 gtk_text_buffer_remove_all_tags(text_buffer
, start
, end
);
76 g_signal_handler_disconnect (text_buffer
, remove_handler_id
);
81 PangoFontDescription
*font_description
= attr
.GetFont().GetNativeFontInfo()->description
;
82 font_string
= pango_font_description_to_string(font_description
);
83 g_snprintf(buf
, sizeof(buf
), "WXFONT %s", font_string
);
84 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
87 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
88 "font-desc", font_description
,
90 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
93 if (attr
.GetFont().GetUnderlined())
95 g_snprintf(buf
, sizeof(buf
), "WXFONTUNDERLINE");
96 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
99 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
100 "underline-set", TRUE
,
101 "underline", PANGO_UNDERLINE_SINGLE
,
103 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
107 if (attr
.HasTextColour())
109 GdkColor
*colFg
= attr
.GetTextColour().GetColor();
110 g_snprintf(buf
, sizeof(buf
), "WXFORECOLOR %d %d %d",
111 colFg
->red
, colFg
->green
, colFg
->blue
);
112 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
115 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
116 "foreground-gdk", colFg
, NULL
);
117 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
120 if (attr
.HasBackgroundColour())
122 GdkColor
*colBg
= attr
.GetBackgroundColour().GetColor();
123 g_snprintf(buf
, sizeof(buf
), "WXBACKCOLOR %d %d %d",
124 colBg
->red
, colBg
->green
, colBg
->blue
);
125 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
128 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
129 "background-gdk", colBg
, NULL
);
130 gtk_text_buffer_apply_tag (text_buffer
, tag
, start
, end
);
133 if (attr
.HasAlignment())
135 GtkTextIter para_start
, para_end
= *end
;
136 gtk_text_buffer_get_iter_at_line( text_buffer
,
138 gtk_text_iter_get_line(start
) );
139 gtk_text_iter_forward_line(¶_end
);
141 remove_handler_id
= g_signal_connect (text_buffer
, "remove_tag",
142 G_CALLBACK(wxGtkOnRemoveTag
),
143 gpointer("WXALIGNMENT"));
144 gtk_text_buffer_remove_all_tags( text_buffer
, ¶_start
, ¶_end
);
145 g_signal_handler_disconnect (text_buffer
, remove_handler_id
);
147 GtkJustification align
;
148 switch (attr
.GetAlignment())
151 align
= GTK_JUSTIFY_LEFT
;
153 case wxTEXT_ALIGNMENT_RIGHT
:
154 align
= GTK_JUSTIFY_RIGHT
;
156 case wxTEXT_ALIGNMENT_CENTER
:
157 align
= GTK_JUSTIFY_CENTER
;
159 // gtk+ doesn't support justify as of gtk+-2.7.4
162 g_snprintf(buf
, sizeof(buf
), "WXALIGNMENT %d", align
);
163 tag
= gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer
),
166 tag
= gtk_text_buffer_create_tag( text_buffer
, buf
,
167 "justification", align
, NULL
);
168 gtk_text_buffer_apply_tag( text_buffer
, tag
, ¶_start
, ¶_end
);
174 static void wxGtkTextInsert(GtkWidget
*text
,
175 GtkTextBuffer
*text_buffer
,
176 const wxTextAttr
& attr
,
177 const wxCharBuffer
& buffer
)
181 GtkTextIter iter
, start
;
183 gtk_text_buffer_get_iter_at_mark( text_buffer
, &iter
,
184 gtk_text_buffer_get_insert (text_buffer
) );
185 start_offset
= gtk_text_iter_get_offset (&iter
);
186 gtk_text_buffer_insert( text_buffer
, &iter
, buffer
, strlen(buffer
) );
188 gtk_text_buffer_get_iter_at_offset (text_buffer
, &start
, start_offset
);
190 wxGtkTextApplyTagsFromAttr(text_buffer
, attr
, &start
, &iter
);
194 // ----------------------------------------------------------------------------
195 // "insert_text" for GtkEntry
196 // ----------------------------------------------------------------------------
200 gtk_insert_text_callback(GtkEditable
*editable
,
201 const gchar
*new_text
,
202 gint new_text_length
,
207 wxapp_install_idle_handler();
209 // we should only be called if we have a max len limit at all
210 GtkEntry
*entry
= GTK_ENTRY (editable
);
212 wxCHECK_RET( entry
->text_max_length
, _T("shouldn't be called") );
214 // check that we don't overflow the max length limit
216 // FIXME: this doesn't work when we paste a string which is going to be
218 if ( entry
->text_length
== entry
->text_max_length
)
220 // we don't need to run the base class version at all
221 g_signal_stop_emission_by_name (editable
, "insert_text");
223 // remember that the next changed signal is to be ignored to avoid
224 // generating a dummy wxEVT_COMMAND_TEXT_UPDATED event
225 win
->IgnoreNextTextUpdate();
227 // and generate the correct one ourselves
228 wxCommandEvent
event(wxEVT_COMMAND_TEXT_MAXLEN
, win
->GetId());
229 event
.SetEventObject(win
);
230 event
.SetString(win
->GetValue());
231 win
->GetEventHandler()->ProcessEvent( event
);
236 // Implementation of wxTE_AUTO_URL for wxGTK2 by Mart Raudsepp,
240 au_apply_tag_callback(GtkTextBuffer
*buffer
,
246 if(tag
== gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl"))
247 g_signal_stop_emission_by_name (buffer
, "apply_tag");
251 //-----------------------------------------------------------------------------
252 // GtkTextCharPredicates for gtk_text_iter_*_find_char
253 //-----------------------------------------------------------------------------
257 pred_whitespace (gunichar ch
, gpointer user_data
)
259 return g_unichar_isspace(ch
);
265 pred_non_whitespace (gunichar ch
, gpointer user_data
)
267 return !g_unichar_isspace(ch
);
273 pred_nonpunct (gunichar ch
, gpointer user_data
)
275 return !g_unichar_ispunct(ch
);
281 pred_nonpunct_or_slash (gunichar ch
, gpointer user_data
)
283 return !g_unichar_ispunct(ch
) || ch
== '/';
287 //-----------------------------------------------------------------------------
288 // Check for links between s and e and correct tags as necessary
289 //-----------------------------------------------------------------------------
291 // This function should be made match better while being efficient at one point.
292 // Most probably with a row of regular expressions.
295 au_check_word( GtkTextIter
*s
, GtkTextIter
*e
)
297 static const char *URIPrefixes
[] =
315 GtkTextIter start
= *s
, end
= *e
;
316 GtkTextBuffer
*buffer
= gtk_text_iter_get_buffer(s
);
318 // Get our special link tag
319 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl");
321 // Get rid of punctuation from beginning and end.
322 // Might want to move this to au_check_range if an improved link checking doesn't
323 // use some intelligent punctuation checking itself (beware of undesired iter modifications).
324 if(g_unichar_ispunct( gtk_text_iter_get_char( &start
) ) )
325 gtk_text_iter_forward_find_char( &start
, pred_nonpunct
, NULL
, e
);
327 gtk_text_iter_backward_find_char( &end
, pred_nonpunct_or_slash
, NULL
, &start
);
328 gtk_text_iter_forward_char(&end
);
330 gchar
* text
= gtk_text_iter_get_text( &start
, &end
);
331 size_t len
= strlen(text
), prefix_len
;
334 for( n
= 0; n
< WXSIZEOF(URIPrefixes
); ++n
)
336 prefix_len
= strlen(URIPrefixes
[n
]);
337 if((len
> prefix_len
) && !strncasecmp(text
, URIPrefixes
[n
], prefix_len
))
341 if(n
< WXSIZEOF(URIPrefixes
))
343 gulong signal_id
= g_signal_handler_find (buffer
,
344 (GSignalMatchType
) (G_SIGNAL_MATCH_FUNC
),
346 (gpointer
)au_apply_tag_callback
, NULL
);
348 g_signal_handler_block (buffer
, signal_id
);
349 gtk_text_buffer_apply_tag(buffer
, tag
, &start
, &end
);
350 g_signal_handler_unblock (buffer
, signal_id
);
357 au_check_range(GtkTextIter
*s
,
358 GtkTextIter
*range_end
)
360 GtkTextIter range_start
= *s
;
361 GtkTextIter word_end
;
362 GtkTextBuffer
*buffer
= gtk_text_iter_get_buffer(s
);
363 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buffer
), "wxUrl");
365 gtk_text_buffer_remove_tag(buffer
, tag
, s
, range_end
);
367 if(g_unichar_isspace(gtk_text_iter_get_char(&range_start
)))
368 gtk_text_iter_forward_find_char(&range_start
, pred_non_whitespace
, NULL
, range_end
);
370 while(!gtk_text_iter_equal(&range_start
, range_end
))
372 word_end
= range_start
;
373 gtk_text_iter_forward_find_char(&word_end
, pred_whitespace
, NULL
, range_end
);
375 // Now we should have a word delimited by range_start and word_end, correct link tags
376 au_check_word(&range_start
, &word_end
);
378 range_start
= word_end
;
379 gtk_text_iter_forward_find_char(&range_start
, pred_non_whitespace
, NULL
, range_end
);
384 //-----------------------------------------------------------------------------
385 // "insert-text" for GtkTextBuffer
386 //-----------------------------------------------------------------------------
390 au_insert_text_callback(GtkTextBuffer
*buffer
,
396 if (!len
|| !(win
->GetWindowStyleFlag() & wxTE_AUTO_URL
) )
399 GtkTextIter start
= *end
;
400 gtk_text_iter_backward_chars(&start
, g_utf8_strlen(text
, len
));
402 GtkTextIter line_start
= start
;
403 GtkTextIter line_end
= *end
;
404 GtkTextIter words_start
= start
;
405 GtkTextIter words_end
= *end
;
407 gtk_text_iter_set_line(&line_start
, gtk_text_iter_get_line(&start
));
408 gtk_text_iter_forward_to_line_end(&line_end
);
409 gtk_text_iter_backward_find_char(&words_start
, pred_whitespace
, NULL
, &line_start
);
410 gtk_text_iter_forward_find_char(&words_end
, pred_whitespace
, NULL
, &line_end
);
412 au_check_range(&words_start
, &words_end
);
416 //-----------------------------------------------------------------------------
417 // "delete-range" for GtkTextBuffer
418 //-----------------------------------------------------------------------------
422 au_delete_range_callback(GtkTextBuffer
*buffer
,
427 if( !(win
->GetWindowStyleFlag() & wxTE_AUTO_URL
) )
430 GtkTextIter line_start
= *start
, line_end
= *end
;
432 gtk_text_iter_set_line(&line_start
, gtk_text_iter_get_line(start
));
433 gtk_text_iter_forward_to_line_end(&line_end
);
434 gtk_text_iter_backward_find_char(start
, pred_whitespace
, NULL
, &line_start
);
435 gtk_text_iter_forward_find_char(end
, pred_whitespace
, NULL
, &line_end
);
437 au_check_range(start
, end
);
442 //-----------------------------------------------------------------------------
444 //-----------------------------------------------------------------------------
448 gtk_text_changed_callback( GtkWidget
*widget
, wxTextCtrl
*win
)
450 if ( win
->IgnoreTextUpdate() )
453 if (!win
->m_hasVMT
) return;
456 wxapp_install_idle_handler();
460 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->GetId() );
461 event
.SetEventObject( win
);
462 win
->GetEventHandler()->ProcessEvent( event
);
466 //-----------------------------------------------------------------------------
467 // "expose_event" from scrolled window and textview
468 //-----------------------------------------------------------------------------
472 gtk_text_exposed_callback( GtkWidget
*widget
, GdkEventExpose
*event
, wxTextCtrl
*win
)
479 //-----------------------------------------------------------------------------
481 //-----------------------------------------------------------------------------
483 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
485 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
486 EVT_CHAR(wxTextCtrl::OnChar
)
488 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
489 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
490 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
491 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
492 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
494 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
495 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
496 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
497 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
498 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
500 // wxTE_AUTO_URL wxTextUrl support. Currently only creates
501 // wxTextUrlEvent in the same cases as wxMSW, more can be added here.
502 EVT_MOTION (wxTextCtrl::OnUrlMouseEvent
)
503 EVT_LEFT_DOWN (wxTextCtrl::OnUrlMouseEvent
)
504 EVT_LEFT_UP (wxTextCtrl::OnUrlMouseEvent
)
505 EVT_LEFT_DCLICK (wxTextCtrl::OnUrlMouseEvent
)
506 EVT_RIGHT_DOWN (wxTextCtrl::OnUrlMouseEvent
)
507 EVT_RIGHT_UP (wxTextCtrl::OnUrlMouseEvent
)
508 EVT_RIGHT_DCLICK(wxTextCtrl::OnUrlMouseEvent
)
511 void wxTextCtrl::Init()
515 SetUpdateFont(false);
517 m_vScrollbar
= (GtkWidget
*)NULL
;
519 m_gdkHandCursor
= NULL
;
520 m_gdkXTermCursor
= NULL
;
523 wxTextCtrl::~wxTextCtrl()
526 gdk_cursor_unref(m_gdkHandCursor
);
528 gdk_cursor_unref(m_gdkXTermCursor
);
531 wxTextCtrl::wxTextCtrl( wxWindow
*parent
,
533 const wxString
&value
,
537 const wxValidator
& validator
,
538 const wxString
&name
)
542 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
545 bool wxTextCtrl::Create( wxWindow
*parent
,
547 const wxString
&value
,
551 const wxValidator
& validator
,
552 const wxString
&name
)
555 m_acceptsFocus
= true;
557 if (!PreCreation( parent
, pos
, size
) ||
558 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
560 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
565 m_vScrollbarVisible
= false;
567 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
572 m_text
= gtk_text_view_new();
574 m_buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text
) );
576 // create scrolled window
577 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
578 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( m_widget
),
579 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
581 // Insert view into scrolled window
582 gtk_container_add( GTK_CONTAINER(m_widget
), m_text
);
584 // translate wx wrapping style to GTK+
586 if ( HasFlag( wxTE_DONTWRAP
) )
587 wrap
= GTK_WRAP_NONE
;
588 else if ( HasFlag( wxTE_CHARWRAP
) )
589 wrap
= GTK_WRAP_CHAR
;
590 else if ( HasFlag( wxTE_WORDWRAP
) )
591 wrap
= GTK_WRAP_WORD
;
592 else // HasFlag(wxTE_BESTWRAP) always true as wxTE_BESTWRAP == 0
594 // GTK_WRAP_WORD_CHAR seems to be new in GTK+ 2.4
596 if ( !gtk_check_version(2,4,0) )
598 wrap
= GTK_WRAP_WORD_CHAR
;
602 wrap
= GTK_WRAP_WORD
;
605 gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text
), wrap
);
607 GtkScrolledWindowSetBorder(m_widget
, style
);
609 gtk_widget_add_events( GTK_WIDGET(m_text
), GDK_ENTER_NOTIFY_MASK
| GDK_LEAVE_NOTIFY_MASK
);
611 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
615 // a single-line text control: no need for scrollbars
617 m_text
= gtk_entry_new();
619 if (style
& wxNO_BORDER
)
620 g_object_set( GTK_ENTRY(m_text
), "has-frame", FALSE
, NULL
);
623 m_parent
->DoAddChild( this );
625 m_focusWidget
= m_text
;
631 gtk_widget_show(m_text
);
632 SetVScrollAdjustment(gtk_scrolled_window_get_vadjustment((GtkScrolledWindow
*)m_widget
));
640 if (style
& wxTE_PASSWORD
)
643 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
646 if (style
& wxTE_READONLY
)
649 gtk_editable_set_editable( GTK_EDITABLE(m_text
), FALSE
);
651 gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text
), FALSE
);
656 if (style
& wxTE_RIGHT
)
657 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_RIGHT
);
658 else if (style
& wxTE_CENTRE
)
659 gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text
), GTK_JUSTIFY_CENTER
);
660 // Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
665 // gtk_entry_set_alignment was introduced in gtk+-2.3.5
666 if (!gtk_check_version(2,4,0))
668 if (style
& wxTE_RIGHT
)
669 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 1.0 );
670 else if (style
& wxTE_CENTRE
)
671 gtk_entry_set_alignment( GTK_ENTRY(m_text
), 0.5 );
676 // We want to be notified about text changes.
679 g_signal_connect (m_buffer
, "changed",
680 G_CALLBACK (gtk_text_changed_callback
), this);
682 // .. and handle URLs on multi-line controls with wxTE_AUTO_URL style
683 if (style
& wxTE_AUTO_URL
)
685 GtkTextIter start
, end
;
686 m_gdkHandCursor
= gdk_cursor_new(GDK_HAND2
);
687 m_gdkXTermCursor
= gdk_cursor_new(GDK_XTERM
);
689 // We create our wxUrl tag here for slight efficiency gain - we
690 // don't have to check for the tag existance in callbacks,
691 // hereby it's guaranteed to exist.
692 gtk_text_buffer_create_tag(m_buffer
, "wxUrl",
693 "foreground", "blue",
694 "underline", PANGO_UNDERLINE_SINGLE
,
697 // Check for URLs after each text change
698 g_signal_connect_after (m_buffer
, "insert_text",
699 G_CALLBACK (au_insert_text_callback
), this);
700 g_signal_connect_after (m_buffer
, "delete_range",
701 G_CALLBACK (au_delete_range_callback
), this);
703 // Block all wxUrl tag applying unless we do it ourselves, in which case we
704 // block this callback temporarily. This takes care of gtk+ internal
705 // gtk_text_buffer_insert_range* calls that would copy our URL tag otherwise,
706 // which is undesired because only a part of the URL might be copied.
707 // The insert-text signal emitted inside it will take care of newly formed
708 // or wholly copied URLs.
709 g_signal_connect (m_buffer
, "apply_tag",
710 G_CALLBACK (au_apply_tag_callback
), NULL
);
712 // Check for URLs in the initial string passed to Create
713 gtk_text_buffer_get_start_iter(m_buffer
, &start
);
714 gtk_text_buffer_get_end_iter(m_buffer
, &end
);
715 au_check_range(&start
, &end
);
720 g_signal_connect (m_text
, "changed",
721 G_CALLBACK (gtk_text_changed_callback
), this);
724 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
726 wxTextAttr
attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont());
727 SetDefaultStyle( attrDef
);
733 void wxTextCtrl::CalculateScrollbar()
737 wxString
wxTextCtrl::GetValue() const
739 wxCHECK_MSG( m_text
!= NULL
, wxEmptyString
, wxT("invalid text ctrl") );
742 if (m_windowStyle
& wxTE_MULTILINE
)
745 gtk_text_buffer_get_start_iter( m_buffer
, &start
);
747 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
748 gchar
*text
= gtk_text_buffer_get_text( m_buffer
, &start
, &end
, TRUE
);
750 const wxWxCharBuffer buf
= wxGTK_CONV_BACK(text
);
758 const gchar
*text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
759 const wxWxCharBuffer buf
= wxGTK_CONV_BACK( text
);
767 void wxTextCtrl::SetValue( const wxString
&value
)
769 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
771 if (m_windowStyle
& wxTE_MULTILINE
)
773 const wxCharBuffer
buffer(wxGTK_CONV(value
));
776 // what else can we do? at least don't crash...
780 if (gtk_text_buffer_get_char_count(m_buffer
) != 0)
781 IgnoreNextTextUpdate();
783 gtk_text_buffer_set_text( m_buffer
, buffer
, strlen(buffer
) );
787 // gtk_entry_set_text() emits two "changed" signals because internally
788 // it calls gtk_editable_delete_text() and gtk_editable_insert_text()
789 // but we want to have only one event
790 IgnoreNextTextUpdate();
792 gtk_entry_set_text( GTK_ENTRY(m_text
), wxGTK_CONV(value
) );
795 // GRG, Jun/2000: Changed this after a lot of discussion in
796 // the lists. wxWidgets 2.2 will have a set of flags to
797 // customize this behaviour.
798 SetInsertionPoint(0);
803 void wxTextCtrl::WriteText( const wxString
&text
)
805 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
810 const wxCharBuffer
buffer(wxGTK_CONV(text
));
813 // what else can we do? at least don't crash...
817 // gtk_text_changed_callback() will set m_modified to true but m_modified
818 // shouldn't be changed by the program writing to the text control itself,
819 // so save the old value and restore when we're done
820 bool oldModified
= m_modified
;
822 if ( m_windowStyle
& wxTE_MULTILINE
)
824 // First remove the selection if there is one
825 // TODO: Is there an easier GTK specific way to do this?
827 GetSelection(&from
, &to
);
832 wxGtkTextInsert( m_text
, m_buffer
, m_defaultStyle
, buffer
);
834 GtkAdjustment
*adj
= gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(m_widget
) );
835 // Scroll to cursor, but only if scrollbar thumb is at the very bottom
836 if ( wxIsSameDouble(adj
->value
, adj
->upper
- adj
->page_size
) )
838 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
),
839 gtk_text_buffer_get_insert( m_buffer
), 0.0, FALSE
, 0.0, 1.0 );
844 // First remove the selection if there is one
845 gtk_editable_delete_selection( GTK_EDITABLE(m_text
) );
847 // This moves the cursor pos to behind the inserted text.
848 gint len
= gtk_editable_get_position(GTK_EDITABLE(m_text
));
850 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buffer
, strlen(buffer
), &len
);
852 // Bring entry's cursor uptodate.
853 gtk_editable_set_position( GTK_EDITABLE(m_text
), len
);
856 m_modified
= oldModified
;
859 void wxTextCtrl::AppendText( const wxString
&text
)
861 SetInsertionPointEnd();
865 wxString
wxTextCtrl::GetLineText( long lineNo
) const
867 if (m_windowStyle
& wxTE_MULTILINE
)
870 gtk_text_buffer_get_iter_at_line(m_buffer
,&line
,lineNo
);
871 GtkTextIter end
= line
;
872 gtk_text_iter_forward_to_line_end(&end
);
873 gchar
*text
= gtk_text_buffer_get_text(m_buffer
,&line
,&end
,TRUE
);
874 wxString
result(wxGTK_CONV_BACK(text
));
880 if (lineNo
== 0) return GetValue();
881 return wxEmptyString
;
885 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
887 /* If you implement this, don't forget to update the documentation!
888 * (file docs/latex/wx/text.tex) */
889 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
892 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
894 if ( m_windowStyle
& wxTE_MULTILINE
)
897 gtk_text_buffer_get_iter_at_offset(m_buffer
, &iter
, pos
);
898 if (gtk_text_iter_is_end(&iter
))
901 *y
= gtk_text_iter_get_line(&iter
);
902 *x
= gtk_text_iter_get_line_offset(&iter
);
904 else // single line control
906 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
913 // index out of bounds
921 long wxTextCtrl::XYToPosition(long x
, long y
) const
923 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
926 if (y
>= gtk_text_buffer_get_line_count (m_buffer
))
929 gtk_text_buffer_get_iter_at_line(m_buffer
, &iter
, y
);
930 if (x
>= gtk_text_iter_get_chars_in_line (&iter
))
933 return gtk_text_iter_get_offset(&iter
) + x
;
936 int wxTextCtrl::GetLineLength(long lineNo
) const
938 if (m_windowStyle
& wxTE_MULTILINE
)
940 int last_line
= gtk_text_buffer_get_line_count( m_buffer
) - 1;
941 if (lineNo
> last_line
)
945 gtk_text_buffer_get_iter_at_line(m_buffer
, &iter
, lineNo
);
946 // get_chars_in_line return includes paragraph delimiters, so need to subtract 1 IF it is not the last line
947 return gtk_text_iter_get_chars_in_line(&iter
) - ((lineNo
== last_line
) ? 0 : 1);
951 wxString str
= GetLineText (lineNo
);
952 return (int) str
.length();
956 int wxTextCtrl::GetNumberOfLines() const
958 if ( m_windowStyle
& wxTE_MULTILINE
)
961 gtk_text_buffer_get_iter_at_offset( m_buffer
, &iter
, 0 );
963 // move forward by one display line until the end is reached
965 while ( gtk_text_view_forward_display_line(GTK_TEXT_VIEW(m_text
), &iter
) )
970 // If the last character in the text buffer is a newline,
971 // gtk_text_view_forward_display_line() will return false without that
972 // line being counted. Must add one manually in that case.
973 GtkTextIter lastCharIter
;
974 gtk_text_buffer_get_iter_at_offset
978 gtk_text_buffer_get_char_count(m_buffer
) - 1
980 gchar lastChar
= gtk_text_iter_get_char( &lastCharIter
);
981 if ( lastChar
== wxT('\n') )
992 void wxTextCtrl::SetInsertionPoint( long pos
)
994 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
999 gtk_text_buffer_get_iter_at_offset( m_buffer
, &iter
, pos
);
1000 gtk_text_buffer_place_cursor( m_buffer
, &iter
);
1001 gtk_text_view_scroll_mark_onscreen
1003 GTK_TEXT_VIEW(m_text
),
1004 gtk_text_buffer_get_insert( m_buffer
)
1009 // FIXME: Is the editable's cursor really uptodate without double set_position in GTK2?
1010 gtk_editable_set_position(GTK_EDITABLE(m_text
), int(pos
));
1014 void wxTextCtrl::SetInsertionPointEnd()
1016 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1018 if (m_windowStyle
& wxTE_MULTILINE
)
1021 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
1022 gtk_text_buffer_place_cursor( m_buffer
, &end
);
1026 gtk_editable_set_position( GTK_EDITABLE(m_text
), -1 );
1030 void wxTextCtrl::SetEditable( bool editable
)
1032 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1034 if (m_windowStyle
& wxTE_MULTILINE
)
1036 gtk_text_view_set_editable( GTK_TEXT_VIEW(m_text
), editable
);
1040 gtk_editable_set_editable( GTK_EDITABLE(m_text
), editable
);
1044 bool wxTextCtrl::Enable( bool enable
)
1046 if (!wxWindowBase::Enable(enable
))
1052 if (m_windowStyle
& wxTE_MULTILINE
)
1054 SetEditable( enable
);
1058 gtk_widget_set_sensitive( m_text
, enable
);
1064 // wxGTK-specific: called recursively by Enable,
1065 // to give widgets an oppprtunity to correct their colours after they
1066 // have been changed by Enable
1067 void wxTextCtrl::OnParentEnable( bool enable
)
1069 // If we have a custom background colour, we use this colour in both
1070 // disabled and enabled mode, or we end up with a different colour under the
1072 wxColour oldColour
= GetBackgroundColour();
1075 // Need to set twice or it'll optimize the useful stuff out
1076 if (oldColour
== * wxWHITE
)
1077 SetBackgroundColour(*wxBLACK
);
1079 SetBackgroundColour(*wxWHITE
);
1080 SetBackgroundColour(oldColour
);
1084 void wxTextCtrl::MarkDirty()
1089 void wxTextCtrl::DiscardEdits()
1094 // ----------------------------------------------------------------------------
1095 // max text length support
1096 // ----------------------------------------------------------------------------
1098 void wxTextCtrl::IgnoreNextTextUpdate()
1100 m_ignoreNextUpdate
= true;
1103 bool wxTextCtrl::IgnoreTextUpdate()
1105 if ( m_ignoreNextUpdate
)
1107 m_ignoreNextUpdate
= false;
1115 void wxTextCtrl::SetMaxLength(unsigned long len
)
1117 if ( !HasFlag(wxTE_MULTILINE
) )
1119 gtk_entry_set_max_length(GTK_ENTRY(m_text
), len
);
1121 // there is a bug in GTK+ 1.2.x: "changed" signal is emitted even if
1122 // we had tried to enter more text than allowed by max text length and
1123 // the text wasn't really changed
1125 // to detect this and generate TEXT_MAXLEN event instead of
1126 // TEXT_CHANGED one in this case we also catch "insert_text" signal
1128 // when max len is set to 0 we disconnect our handler as it means that
1129 // we shouldn't check anything any more
1132 g_signal_connect (m_text
, "insert_text",
1133 G_CALLBACK (gtk_insert_text_callback
), this);
1137 g_signal_handlers_disconnect_by_func (m_text
,
1138 (gpointer
) gtk_insert_text_callback
, this);
1143 void wxTextCtrl::SetSelection( long from
, long to
)
1145 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1147 if (from
== -1 && to
== -1)
1150 to
= GetValue().length();
1153 if (m_windowStyle
& wxTE_MULTILINE
)
1155 GtkTextIter fromi
, toi
;
1156 gtk_text_buffer_get_iter_at_offset( m_buffer
, &fromi
, from
);
1157 gtk_text_buffer_get_iter_at_offset( m_buffer
, &toi
, to
);
1159 gtk_text_buffer_place_cursor( m_buffer
, &toi
);
1160 gtk_text_buffer_move_mark_by_name( m_buffer
, "selection_bound", &fromi
);
1164 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1168 void wxTextCtrl::ShowPosition( long pos
)
1170 if (m_windowStyle
& wxTE_MULTILINE
)
1173 gtk_text_buffer_get_start_iter( m_buffer
, &iter
);
1174 gtk_text_iter_set_offset( &iter
, pos
);
1175 GtkTextMark
*mark
= gtk_text_buffer_create_mark( m_buffer
, NULL
, &iter
, TRUE
);
1176 gtk_text_view_scroll_to_mark( GTK_TEXT_VIEW(m_text
), mark
, 0.0, FALSE
, 0.0, 0.0 );
1180 wxTextCtrlHitTestResult
1181 wxTextCtrl::HitTest(const wxPoint
& pt
, long *pos
) const
1183 if ( !IsMultiLine() )
1186 return wxTE_HT_UNKNOWN
;
1190 gtk_text_view_window_to_buffer_coords
1192 GTK_TEXT_VIEW(m_text
),
1193 GTK_TEXT_WINDOW_TEXT
,
1199 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &iter
, x
, y
);
1201 *pos
= gtk_text_iter_get_offset(&iter
);
1203 return wxTE_HT_ON_TEXT
;
1206 long wxTextCtrl::GetInsertionPoint() const
1208 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1210 if (m_windowStyle
& wxTE_MULTILINE
)
1212 // There is no direct accessor for the cursor, but
1213 // internally, the cursor is the "mark" called
1214 // "insert" in the text view's btree structure.
1216 GtkTextMark
*mark
= gtk_text_buffer_get_insert( m_buffer
);
1218 gtk_text_buffer_get_iter_at_mark( m_buffer
, &cursor
, mark
);
1220 return gtk_text_iter_get_offset( &cursor
);
1224 return (long) gtk_editable_get_position(GTK_EDITABLE(m_text
));
1228 wxTextPos
wxTextCtrl::GetLastPosition() const
1230 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
1234 if (m_windowStyle
& wxTE_MULTILINE
)
1237 gtk_text_buffer_get_end_iter( m_buffer
, &end
);
1239 pos
= gtk_text_iter_get_offset( &end
);
1243 pos
= GTK_ENTRY(m_text
)->text_length
;
1249 void wxTextCtrl::Remove( long from
, long to
)
1251 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1253 if (m_windowStyle
& wxTE_MULTILINE
)
1255 GtkTextIter fromi
, toi
;
1256 gtk_text_buffer_get_iter_at_offset( m_buffer
, &fromi
, from
);
1257 gtk_text_buffer_get_iter_at_offset( m_buffer
, &toi
, to
);
1259 gtk_text_buffer_delete( m_buffer
, &fromi
, &toi
);
1262 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
1265 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
1267 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1273 SetInsertionPoint( from
);
1278 void wxTextCtrl::Cut()
1280 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1282 if (m_windowStyle
& wxTE_MULTILINE
)
1283 g_signal_emit_by_name (m_text
, "cut-clipboard");
1285 gtk_editable_cut_clipboard(GTK_EDITABLE(m_text
));
1288 void wxTextCtrl::Copy()
1290 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1292 if (m_windowStyle
& wxTE_MULTILINE
)
1293 g_signal_emit_by_name (m_text
, "copy-clipboard");
1295 gtk_editable_copy_clipboard(GTK_EDITABLE(m_text
));
1298 void wxTextCtrl::Paste()
1300 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1302 if (m_windowStyle
& wxTE_MULTILINE
)
1303 g_signal_emit_by_name (m_text
, "paste-clipboard");
1305 gtk_editable_paste_clipboard(GTK_EDITABLE(m_text
));
1309 void wxTextCtrl::Undo()
1312 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
1315 void wxTextCtrl::Redo()
1318 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
1321 bool wxTextCtrl::CanUndo() const
1324 //wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
1328 bool wxTextCtrl::CanRedo() const
1331 //wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
1335 // If the return values from and to are the same, there is no
1337 void wxTextCtrl::GetSelection(long* fromOut
, long* toOut
) const
1339 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1343 bool haveSelection
= false;
1345 if (m_windowStyle
& wxTE_MULTILINE
)
1347 GtkTextIter ifrom
, ito
;
1348 if ( gtk_text_buffer_get_selection_bounds(m_buffer
, &ifrom
, &ito
) )
1350 haveSelection
= true;
1351 from
= gtk_text_iter_get_offset(&ifrom
);
1352 to
= gtk_text_iter_get_offset(&ito
);
1355 else // not multi-line
1357 if ( gtk_editable_get_selection_bounds( GTK_EDITABLE(m_text
),
1360 haveSelection
= true;
1364 if (! haveSelection
)
1365 from
= to
= GetInsertionPoint();
1369 // exchange them to be compatible with wxMSW
1382 bool wxTextCtrl::IsEditable() const
1384 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1386 if (m_windowStyle
& wxTE_MULTILINE
)
1388 return gtk_text_view_get_editable(GTK_TEXT_VIEW(m_text
));
1392 return gtk_editable_get_editable(GTK_EDITABLE(m_text
));
1396 bool wxTextCtrl::IsModified() const
1401 void wxTextCtrl::Clear()
1403 SetValue( wxEmptyString
);
1406 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
1408 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
1410 if ((key_event
.GetKeyCode() == WXK_RETURN
) && (m_windowStyle
& wxTE_PROCESS_ENTER
))
1412 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1413 event
.SetEventObject(this);
1414 event
.SetString(GetValue());
1415 if (GetEventHandler()->ProcessEvent(event
)) return;
1418 if ((key_event
.GetKeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
1420 // This will invoke the dialog default action, such
1421 // as the clicking the default button.
1423 wxWindow
*top_frame
= m_parent
;
1424 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
1425 top_frame
= top_frame
->GetParent();
1427 if (top_frame
&& GTK_IS_WINDOW(top_frame
->m_widget
))
1429 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
1431 if (window
->default_widget
)
1433 gtk_widget_activate (window
->default_widget
);
1442 GtkWidget
* wxTextCtrl::GetConnectWidget()
1444 return GTK_WIDGET(m_text
);
1447 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
1449 if (m_windowStyle
& wxTE_MULTILINE
)
1451 return window
== gtk_text_view_get_window( GTK_TEXT_VIEW( m_text
), GTK_TEXT_WINDOW_TEXT
); // pure guesswork
1455 return (window
== GTK_ENTRY(m_text
)->text_area
);
1459 // the font will change for subsequent text insertiongs
1460 bool wxTextCtrl::SetFont( const wxFont
&font
)
1462 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1464 if ( !wxTextCtrlBase::SetFont(font
) )
1466 // font didn't change, nothing to do
1470 if ( m_windowStyle
& wxTE_MULTILINE
)
1472 SetUpdateFont(true);
1474 m_defaultStyle
.SetFont(font
);
1476 ChangeFontGlobally();
1482 void wxTextCtrl::ChangeFontGlobally()
1484 // this method is very inefficient and hence should be called as rarely as
1487 // TODO: it can be implemented much more efficiently for GTK2
1488 wxASSERT_MSG( (m_windowStyle
& wxTE_MULTILINE
),
1489 _T("shouldn't be called for single line controls") );
1491 wxString value
= GetValue();
1492 if ( !value
.empty() )
1494 SetUpdateFont(false);
1501 bool wxTextCtrl::SetForegroundColour(const wxColour
& colour
)
1503 if ( !wxControl::SetForegroundColour(colour
) )
1506 // update default fg colour too
1507 m_defaultStyle
.SetTextColour(colour
);
1512 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
1514 wxCHECK_MSG( m_text
!= NULL
, false, wxT("invalid text ctrl") );
1516 if ( !wxControl::SetBackgroundColour( colour
) )
1519 if (!m_backgroundColour
.Ok())
1522 // change active background color too
1523 m_defaultStyle
.SetBackgroundColour( colour
);
1528 bool wxTextCtrl::SetStyle( long start
, long end
, const wxTextAttr
& style
)
1530 if ( m_windowStyle
& wxTE_MULTILINE
)
1532 if ( style
.IsDefault() )
1538 gint l
= gtk_text_buffer_get_char_count( m_buffer
);
1540 wxCHECK_MSG( start
>= 0 && end
<= l
, false,
1541 _T("invalid range in wxTextCtrl::SetStyle") );
1543 GtkTextIter starti
, endi
;
1544 gtk_text_buffer_get_iter_at_offset( m_buffer
, &starti
, start
);
1545 gtk_text_buffer_get_iter_at_offset( m_buffer
, &endi
, end
);
1547 // use the attributes from style which are set in it and fall back
1548 // first to the default style and then to the text control default
1549 // colours for the others
1550 wxTextAttr attr
= wxTextAttr::Combine(style
, m_defaultStyle
, this);
1552 wxGtkTextApplyTagsFromAttr( m_buffer
, attr
, &starti
, &endi
);
1558 // cannot do this for GTK+'s Entry widget
1562 void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle
*style
)
1564 gtk_widget_modify_style(m_text
, style
);
1567 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1572 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1577 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1582 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1587 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1592 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1594 event
.Enable( CanCut() );
1597 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1599 event
.Enable( CanCopy() );
1602 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1604 event
.Enable( CanPaste() );
1607 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1609 event
.Enable( CanUndo() );
1612 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1614 event
.Enable( CanRedo() );
1617 void wxTextCtrl::OnInternalIdle()
1619 wxCursor cursor
= m_cursor
;
1620 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1622 if (g_delayedFocus
== this)
1624 if (GTK_WIDGET_REALIZED(m_widget
))
1626 gtk_widget_grab_focus( m_widget
);
1627 g_delayedFocus
= NULL
;
1631 if (wxUpdateUIEvent::CanUpdate(this))
1632 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1635 wxSize
wxTextCtrl::DoGetBestSize() const
1637 // FIXME should be different for multi-line controls...
1638 wxSize
ret( wxControl::DoGetBestSize() );
1639 wxSize
best(80, ret
.y
);
1640 CacheBestSize(best
);
1644 // ----------------------------------------------------------------------------
1646 // ----------------------------------------------------------------------------
1648 void wxTextCtrl::Freeze()
1650 if ( HasFlag(wxTE_MULTILINE
) )
1652 if ( !m_frozenness
++ )
1654 // freeze textview updates and remove buffer
1655 g_signal_connect (m_text
, "expose_event",
1656 G_CALLBACK (gtk_text_exposed_callback
), this);
1657 g_signal_connect (m_widget
, "expose_event",
1658 G_CALLBACK (gtk_text_exposed_callback
), this);
1659 gtk_widget_set_sensitive(m_widget
, false);
1660 g_object_ref(m_buffer
);
1661 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text
), gtk_text_buffer_new(NULL
));
1666 void wxTextCtrl::Thaw()
1668 if ( HasFlag(wxTE_MULTILINE
) )
1670 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1672 if ( !--m_frozenness
)
1674 // Reattach buffer and thaw textview updates
1675 gtk_text_view_set_buffer(GTK_TEXT_VIEW(m_text
), m_buffer
);
1676 g_object_unref(m_buffer
);
1677 gtk_widget_set_sensitive(m_widget
, true);
1678 g_signal_handlers_disconnect_by_func (m_widget
,
1679 (gpointer
) gtk_text_exposed_callback
, this);
1680 g_signal_handlers_disconnect_by_func (m_text
,
1681 (gpointer
) gtk_text_exposed_callback
, this);
1686 // ----------------------------------------------------------------------------
1687 // wxTextUrlEvent passing if style & wxTE_AUTO_URL
1688 // ----------------------------------------------------------------------------
1690 // FIXME: when dragging on a link the sample gets an "Unknown event".
1691 // This might be an excessive event from us or a buggy wxMouseEvent::Moving() or
1692 // a buggy sample, or something else
1693 void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent
& event
)
1696 if(!(m_windowStyle
& wxTE_AUTO_URL
))
1700 GtkTextIter start
, end
;
1701 GtkTextTag
*tag
= gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(m_buffer
),
1704 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(m_text
), GTK_TEXT_WINDOW_WIDGET
,
1705 event
.GetX(), event
.GetY(), &x
, &y
);
1707 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text
), &end
, x
, y
);
1708 if (!gtk_text_iter_has_tag(&end
, tag
))
1710 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text
),
1711 GTK_TEXT_WINDOW_TEXT
), m_gdkXTermCursor
);
1715 gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text
),
1716 GTK_TEXT_WINDOW_TEXT
), m_gdkHandCursor
);
1719 if(!gtk_text_iter_begins_tag(&start
, tag
))
1720 gtk_text_iter_backward_to_tag_toggle(&start
, tag
);
1721 if(!gtk_text_iter_ends_tag(&end
, tag
))
1722 gtk_text_iter_forward_to_tag_toggle(&end
, tag
);
1724 // Native context menu is probably not desired on an URL.
1725 // Consider making this dependant on ProcessEvent(wxTextUrlEvent) return value
1726 if(event
.GetEventType() == wxEVT_RIGHT_DOWN
)
1729 wxTextUrlEvent
url_event(m_windowId
, event
,
1730 gtk_text_iter_get_offset(&start
),
1731 gtk_text_iter_get_offset(&end
));
1733 InitCommandEvent(url_event
);
1734 // Is that a good idea? Seems not (pleasure with gtk_text_view_start_selection_drag)
1735 //event.Skip(!GetEventHandler()->ProcessEvent(url_event));
1736 GetEventHandler()->ProcessEvent(url_event
);
1741 wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1743 return GetDefaultAttributesFromGTKWidget(gtk_entry_new
, true);