void wxTextCtrl::SetInsertionPoint( long pos ) { wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); if ( IsMultiLine() ) { gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); /* we fake a set_point by inserting and deleting. as the user isn't supposed to get to know about this non-sense, we disconnect so that no events are sent to the user program. */ gint tmp = (gint)pos; gtk_editable_insert_text( GTK_EDITABLE(m_text), " ", 1, &tmp ); gtk_editable_delete_text( GTK_EDITABLE(m_text), tmp-1, tmp ); gtk_signal_connect( GTK_OBJECT(m_text), "changed", GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); // bring editable's cursor uptodate. Bug in GTK. SET_EDITABLE_POS(m_text, gtk_text_get_point( GTK_TEXT(m_text) )); } else { gtk_entry_set_position( GTK_ENTRY(m_text), (int)pos ); // Bring editable's cursor uptodate. Bug in GTK. SET_EDITABLE_POS(m_text, (guint32)pos); } }
void wxTextCtrl::WriteText( const wxString &text ) { wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") ); if ( text.empty() ) return; // gtk_text_changed_callback() will set m_modified to true but m_modified // shouldn't be changed by the program writing to the text control itself, // so save the old value and restore when we're done bool oldModified = m_modified; if ( m_windowStyle & wxTE_MULTILINE ) { // After cursor movements, gtk_text_get_point() is wrong by one. gtk_text_set_point( GTK_TEXT(m_text), GET_EDITABLE_POS(m_text) ); // always use m_defaultStyle, even if it is empty as otherwise // resetting the style and appending some more text wouldn't work: if // we don't specify the style explicitly, the old style would be used gtk_editable_delete_selection( GTK_EDITABLE(m_text) ); wxGtkTextInsert(m_text, m_defaultStyle, text.c_str(), text.length()); // we called wxGtkTextInsert with correct font, no need to do anything // in UpdateFontIfNeeded() any longer if ( !text.empty() ) { SetUpdateFont(false); } // Bring editable's cursor back uptodate. SET_EDITABLE_POS(m_text, gtk_text_get_point( GTK_TEXT(m_text) )); } else // single line { // First remove the selection if there is one gtk_editable_delete_selection( GTK_EDITABLE(m_text) ); // This moves the cursor pos to behind the inserted text. gint len = GET_EDITABLE_POS(m_text); gtk_editable_insert_text( GTK_EDITABLE(m_text), text.c_str(), text.length(), &len ); // Bring entry's cursor uptodate. gtk_entry_set_position( GTK_ENTRY(m_text), len ); } m_modified = oldModified; }
gint keyevent(GtkWidget * w, GdkEventKey * event, gpointer data) { Gwidget_t *widget; widget = findwidget((unsigned long) w, G_TEXTWIDGET); if (event->keyval == 65293) { Gbufp = gtk_editable_get_chars(w, pos, -1); pos = gtk_text_get_point(w); if (WTU->func) { /* calls TXTprocess in the case of txtview */ (*WTU->func) (widget - &Gwidgets[0], Gbufp); } } return FALSE; }
bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, long style, const wxValidator& validator, const wxString &name ) { m_needParent = true; m_acceptsFocus = true; if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxTextCtrl creation failed") ); return false; } m_vScrollbarVisible = false; bool multi_line = (style & wxTE_MULTILINE) != 0; if (multi_line) { // create our control ... m_text = gtk_text_new( NULL, NULL ); // ... and put into the upper left hand corner of the table bool bHasHScrollbar = false; m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE); GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); gtk_table_attach( GTK_TABLE(m_widget), m_text, 0, 1, 0, 1, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK), 0, 0); // always wrap words gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE ); // finally, put the vertical scrollbar in the upper right corner m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj ); GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS ); gtk_table_attach(GTK_TABLE(m_widget), m_vScrollbar, 1, 2, 0, 1, GTK_FILL, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK), 0, 0); } else { // a single-line text control: no need for scrollbars m_widget = m_text = gtk_entry_new(); } m_parent->DoAddChild( this ); m_focusWidget = m_text; PostCreation(size); if (multi_line) gtk_widget_show(m_text); if (multi_line) { gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed", (GtkSignalFunc) gtk_scrollbar_changed_callback, (gpointer) this ); // only initialize gs_gtk_text_draw once, starting from the next the // klass::draw will already be wxgtk_text_draw if ( !gs_gtk_text_draw ) { GtkDrawCallback& draw = GTK_WIDGET_CLASS(GTK_OBJECT(m_text)->klass)->draw; gs_gtk_text_draw = draw; draw = wxgtk_text_draw; } } if (!value.empty()) { #if !GTK_CHECK_VERSION(1, 2, 0) // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in // gtk_editable_insert_text() gtk_widget_realize(m_text); #endif // GTK 1.0 gint tmp = 0; #if wxUSE_UNICODE wxWX2MBbuf val = value.mbc_str(); gtk_editable_insert_text( GTK_EDITABLE(m_text), val, strlen(val), &tmp ); #else gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.length(), &tmp ); #endif if (multi_line) { // Bring editable's cursor uptodate. Bug in GTK. SET_EDITABLE_POS(m_text, gtk_text_get_point( GTK_TEXT(m_text) )); } } if (style & wxTE_PASSWORD) { if (!multi_line) gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE ); } if (style & wxTE_READONLY) { if (!multi_line) gtk_entry_set_editable( GTK_ENTRY(m_text), FALSE ); } else { if (multi_line) gtk_text_set_editable( GTK_TEXT(m_text), 1 ); } // We want to be notified about text changes. gtk_signal_connect( GTK_OBJECT(m_text), "changed", GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); m_cursor = wxCursor( wxCURSOR_IBEAM ); wxTextAttr attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont()); SetDefaultStyle( attrDef ); return true; }