static void midorator_entry_perform_completion(MidoratorEntry* e) { char *str = g_strdup(gtk_entry_get_text(GTK_ENTRY(e))); int prelen = 0; if (str[0]) { prelen = g_utf8_offset_to_pointer(str, gtk_editable_get_position(GTK_EDITABLE(e))) - str; str[prelen] = 0; } GList *list = midorator_entry_get_comp_list(e, str); g_free(str); if (!list) return; str = g_strdup(list->data); GList *i; bool crop = false; for (i = list->next; i; i = i->next) { const char *s = i->data; int j; for (j = 0; s[j] && s[j] == str[j]; j++); if (str[j]) { crop = true; str[j] = 0; } } int pos = gtk_editable_get_position(GTK_EDITABLE(e)); gtk_editable_insert_text(GTK_EDITABLE(e), str + prelen, -1, &pos); if (!crop) gtk_editable_insert_text(GTK_EDITABLE(e), " ", -1, &pos); gtk_editable_set_position(GTK_EDITABLE(e), pos); g_free(str); }
static gboolean midorator_entry_key_press_event_cb (MidoratorEntry* e, GdkEventKey* event) { if ((event->state & GDK_CONTROL_MASK) && event->keyval == GDK_a) { gtk_editable_set_position(GTK_EDITABLE(e), 0); } else if ((event->state & GDK_CONTROL_MASK) && event->keyval == GDK_e) { gtk_editable_set_position(GTK_EDITABLE(e), -1); } else if ((event->state & GDK_CONTROL_MASK) && event->keyval == GDK_f) { gtk_editable_set_position(GTK_EDITABLE(e), gtk_editable_get_position(GTK_EDITABLE(e)) + 1); } else if ((event->state & GDK_CONTROL_MASK) && event->keyval == GDK_b) { gtk_editable_set_position(GTK_EDITABLE(e), gtk_editable_get_position(GTK_EDITABLE(e)) - 1); } else if ((event->state & GDK_CONTROL_MASK) && event->keyval == GDK_p) { gtk_editable_set_position(GTK_EDITABLE(e), 0); midorator_entry_history_up(e); } else if ((event->state & GDK_CONTROL_MASK) && event->keyval == GDK_n) { gtk_editable_set_position(GTK_EDITABLE(e), 0); midorator_entry_history_down(e); } else if ((event->state & GDK_CONTROL_MASK) && event->keyval == GDK_w) { const char *t = gtk_entry_get_text(GTK_ENTRY(e)); int pos = gtk_editable_get_position(GTK_EDITABLE(e)); char *i; for (i = g_utf8_offset_to_pointer(t, pos) - 1; i >= t && *i == ' '; i--); for (; i >= t && *i != ' '; i--); i++; int newpos = g_utf8_pointer_to_offset(t, i); gtk_editable_delete_text(GTK_EDITABLE(e), newpos, pos); gtk_editable_set_position(GTK_EDITABLE(e), newpos); } else if (event->keyval == GDK_Escape) { g_signal_emit(e, signals[SIG_CANCEL], 0); } else if (event->keyval == GDK_Tab) { midorator_entry_perform_completion(e); } else if (event->keyval == GDK_Up) { midorator_entry_history_up(e); } else if (event->keyval == GDK_Down) { midorator_entry_history_down(e); } else if (event->keyval == GDK_Page_Up) { gtk_editable_set_position(GTK_EDITABLE(e), 0); midorator_entry_history_up(e); } else if (event->keyval == GDK_Page_Down) { gtk_editable_set_position(GTK_EDITABLE(e), 0); midorator_entry_history_down(e); } else if (event->keyval == GDK_Return) { char *t = g_strdup(gtk_entry_get_text(GTK_ENTRY(e))); g_signal_emit(e, signals[SIG_EXECUTE], 0, t); midorator_entry_history_add(e, t); g_free(t); } else return false; return true; }
void gtkurl_check_all(GtkText *gtktext) { guint origpos; guint pos = 0; guint len; float adj_value; len = gtk_text_get_length(gtktext); adj_value = gtktext->vadj->value; gtk_text_freeze(gtktext); origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); while (pos < len) { while (pos < len && iswordsep(GTK_TEXT_INDEX(gtktext, pos))) pos++; while (pos < len && !iswordsep(GTK_TEXT_INDEX(gtktext, pos))) pos++; if (pos > 0) check_at(gtktext, pos-1); } gtk_text_thaw(gtktext); gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); }
static gint luaH_entry_get_position(lua_State *L) { widget_t *w = luaH_checkudata(L, 1, &widget_class); lua_pushnumber(L, gtk_editable_get_position(GTK_EDITABLE(w->widget))); return 1; }
static void iti_draw_cursor (MateIconTextItem *iti, GdkDrawable *drawable, int x, int y) { int stem_width; int i; int cursor_offset; PangoRectangle pos; GtkEntry *entry; g_return_if_fail (iti->_priv->cursor_gc != NULL); entry = GTK_ENTRY (iti->_priv->entry); cursor_offset = gtk_editable_get_position (GTK_EDITABLE (entry)); pango_layout_get_cursor_pos (iti->_priv->layout, g_utf8_offset_to_pointer (entry->text, cursor_offset) - entry->text, &pos, NULL); stem_width = PANGO_PIXELS (pos.height) / 30 + 1; for (i = 0; i < stem_width; i++) { gdk_draw_line (drawable, iti->_priv->cursor_gc, x + PANGO_PIXELS (pos.x) + i - stem_width / 2, y + PANGO_PIXELS (pos.y), x + PANGO_PIXELS (pos.x) + i - stem_width / 2, y + PANGO_PIXELS (pos.y) + PANGO_PIXELS (pos.height)); } }
static int delete_text_in_gtk_entry(GtkEntry *entry, enum UTextOrigin origin, int former_req_len, int latter_req_len) { gint start_pos, end_pos, current_pos; current_pos = gtk_editable_get_position(GTK_EDITABLE(entry)); switch (origin) { case UTextOrigin_Cursor: if (former_req_len >= 0) { start_pos = current_pos - former_req_len; } else { if (!(~former_req_len & (~UTextExtent_Line | ~UTextExtent_Full))) return -1; start_pos = 0; } if (latter_req_len >= 0) end_pos = current_pos + latter_req_len; else { if (!(~latter_req_len & (~UTextExtent_Line | ~UTextExtent_Full))) return -1; end_pos = gtk_entry_get_text_length(entry); } break; case UTextOrigin_Beginning: start_pos = 0; if (latter_req_len >= 0) end_pos = latter_req_len; else { if (!(~latter_req_len & (~UTextExtent_Line | ~UTextExtent_Full))) return -1; end_pos = gtk_entry_get_text_length(entry); } break; case UTextOrigin_End: if (former_req_len >= 0) start_pos = gtk_entry_get_text_length(entry) - former_req_len; else { if (!(~former_req_len & (~UTextExtent_Line | ~UTextExtent_Full))) return -1; start_pos = 0; } end_pos = gtk_entry_get_text_length(entry); break; case UTextOrigin_Unspecified: default: return -1; } gtk_editable_delete_text(GTK_EDITABLE(entry), start_pos, end_pos); return 0; }
void wxTextEntry::WriteText(const wxString& value) { GtkEditable * const edit = GetEditable(); // remove the selection if there is one and suppress the text change event // generated by this: we only want to generate one event for this change, // not two { EventsSuppressor noevents(this); gtk_editable_delete_selection(edit); } // insert new text at the cursor position gint len = gtk_editable_get_position(edit); gtk_editable_insert_text ( edit, wxGTK_CONV_FONT(value, GetEditableWindow()->GetFont()), -1, // text: length: compute it using strlen() &len // will be updated to position after the text end ); // and move cursor to the end of new text gtk_editable_set_position(edit, len); }
int maskcpf(GtkWidget *widget,GdkEventKey *event,gpointer *poi){ char tt[20]; int bak; gint *j; if(event->keyval == 65288){ //g_print("erro"); bak=0;}else { j = gtk_editable_get_position(GTK_EDITABLE(widget)); if( j == 3) { sprintf(tt,"%s.",gtk_entry_get_text(GTK_ENTRY(widget))); gtk_entry_set_text(GTK_ENTRY(widget),tt); gtk_editable_set_position(GTK_EDITABLE(widget),4); } if( j == 7) { sprintf(tt,"%s.",gtk_entry_get_text(GTK_ENTRY(widget))); gtk_entry_set_text(GTK_ENTRY(widget),tt); gtk_editable_set_position(GTK_EDITABLE(widget),8); } if( j == 11) { sprintf(tt,"%s-",gtk_entry_get_text(GTK_ENTRY(widget))); gtk_entry_set_text(GTK_ENTRY(widget),tt); gtk_editable_set_position(GTK_EDITABLE(widget),12); } } return 0; }
/* entry_insert_text(const char *) {{{*/ void entry_insert_text(const char *text) { int position = gtk_editable_get_position(GTK_EDITABLE(dwb.gui.entry)); gtk_editable_insert_text(GTK_EDITABLE(dwb.gui.entry), text, -1, &position); gtk_editable_set_position(GTK_EDITABLE(dwb.gui.entry), position); }/*}}}*/
/** \brief Manage layout code changes. * * This function is called when the contents of the lyout code changes. * The purpose of this function is to check whether entered character is valid * and to make the configuration "dirty". */ static void layout_code_changed (GtkWidget *widget, gpointer data) { gchar *entry, *end, *j; gint len, pos; /* step 1: ensure that only valid characters are entered (stolen from xlog, tnx pg4i) */ entry = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); if ((len = g_utf8_strlen (entry, -1)) > 0) { end = entry + g_utf8_strlen (entry, -1); for (j = entry; j < end; ++j) { switch (*j) { case '0' ... '9': case ';': dirty = TRUE; /* ensure combo box is set to custom */ if (gtk_combo_box_get_active (GTK_COMBO_BOX(selector)) != PREDEF_NUM-1) { gtk_combo_box_set_active (GTK_COMBO_BOX(selector), PREDEF_NUM-1); } break; default: gdk_beep (); pos = gtk_editable_get_position (GTK_EDITABLE (widget)); gtk_editable_delete_text (GTK_EDITABLE (widget), pos, pos+1); break; } } }
/** \brief Manage name changes. * * This function is called when the contents of the name entry changes. * The primary purpose of this function is to check whether the char length * of the name is greater than zero, if yes enable the OK button of the dialog. */ static void name_changed (GtkWidget *widget, gpointer data) { const gchar *text; gchar *entry, *end, *j; gint len, pos; GtkWidget *dialog = GTK_WIDGET (data); /* step 1: ensure that only valid characters are entered (stolen from xlog, tnx pg4i) */ entry = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); if ((len = g_utf8_strlen (entry, -1)) > 0) { end = entry + g_utf8_strlen (entry, -1); for (j = entry; j < end; ++j) { switch (*j) { case '0' ... '9': case 'a' ... 'z': case 'A' ... 'Z': case '-': case '_': break; default: gdk_beep (); pos = gtk_editable_get_position (GTK_EDITABLE (widget)); gtk_editable_delete_text (GTK_EDITABLE (widget), pos, pos+1); break; } } }
static gint luaH_entry_index(lua_State *L, luakit_token_t token) { widget_t *w = luaH_checkwidget(L, 1); switch(token) { LUAKIT_WIDGET_INDEX_COMMON /* push class methods */ PF_CASE(APPEND, luaH_entry_append) PF_CASE(INSERT, luaH_entry_insert) PF_CASE(SELECT_REGION, luaH_entry_select_region) /* push integer properties */ PI_CASE(POSITION, gtk_editable_get_position(GTK_EDITABLE(w->widget))) /* push string properties */ PS_CASE(TEXT, gtk_entry_get_text(GTK_ENTRY(w->widget))) PS_CASE(FG, g_object_get_data(G_OBJECT(w->widget), "fg")) PS_CASE(BG, g_object_get_data(G_OBJECT(w->widget), "bg")) PS_CASE(FONT, g_object_get_data(G_OBJECT(w->widget), "font")) /* push boolean properties */ PB_CASE(SHOW_FRAME, gtk_entry_get_has_frame(GTK_ENTRY(w->widget))) default: break; } return 0; }
static void autocomplete_protocol_string(GtkWidget *filter_te, gchar *selected_str) { int pos; gchar *filter_str; gchar *pch; /* Get the current filter string */ pos = gtk_editable_get_position(GTK_EDITABLE(filter_te)); filter_str = gtk_editable_get_chars(GTK_EDITABLE(filter_te), 0, pos); /* Start from the end */ pch = filter_str + strlen(filter_str); /* Walk back through string to find last non-punctuation */ while(pch != filter_str) { pch--; if(!g_ascii_isalnum(*pch) && (*pch) != '.' && (*pch) != '_' && (*pch) != '-') { pch++; break; } } if(strncmp(pch, selected_str, pos-(pch-filter_str))) { gtk_editable_delete_text(GTK_EDITABLE(filter_te), (gint) (pch-filter_str), pos); pos = (int) (pch-filter_str); pch = selected_str; } else { pch = (selected_str + strlen(pch)); } gtk_editable_insert_text(GTK_EDITABLE(filter_te), pch, (gint) strlen(pch), &pos); gtk_editable_set_position(GTK_EDITABLE(filter_te), pos); g_free (filter_str); }
/** * Case insensitive substring search for a completion match. * * Based on the default matching function in GtkEntryCompletion. * * This function is called once for each iter in the GtkEntryCompletion's * list of completion entries (model). * * @param completion Completion object to apply this function on * @param key Complete string from the GtkEntry. * @param iter Item in list of autocomplete database to compare key against. * @param user_data Unused. */ static gboolean on_match_func (GtkEntryCompletion *completion, const gchar *key, GtkTreeIter *iter, gpointer user_data) { gchar *item = NULL; gchar *normalized_string; gchar *case_normalized_string; gboolean ret = FALSE; GtkTreeModel *model = gtk_entry_completion_get_model (completion); GtkEditable *e = (GtkEditable*) gtk_entry_completion_get_entry(completion); gint cur_pos = gtk_editable_get_position(e); /* returns 1..* */ gint p = cur_pos; gint var_start; gboolean var_present = FALSE; for (p = cur_pos; p >= 0; p--) { gchar *ss = gtk_editable_get_chars(e, p, cur_pos); if (strncmp(ss, "$(", 2) == 0) { var_start = p+2; var_present = TRUE; g_free(ss); break; } g_free(ss); } if (var_present) { gchar *varname = gtk_editable_get_chars(e, var_start, cur_pos); gtk_tree_model_get (model, iter, COMPL_VARNAME, &item, -1); if (item != NULL) { // Do utf8-safe case insensitive string compare. // Shamelessly stolen from GtkEntryCompletion. normalized_string = g_utf8_normalize (item, -1, G_NORMALIZE_ALL); if (normalized_string != NULL) { case_normalized_string = g_utf8_casefold (normalized_string, -1); if (!g_ascii_strncasecmp(varname, case_normalized_string, strlen (varname))) ret = TRUE; g_free (case_normalized_string); } g_free (normalized_string); } g_free (varname); } g_free (item); return ret; }
static gboolean midorator_entry_restore_focus(MidoratorEntry* e) { if (midorator_entry_is_visible(e)) { int p = gtk_editable_get_position(GTK_EDITABLE(e)); gtk_widget_grab_focus(GTK_WIDGET(e)); gtk_editable_set_position(GTK_EDITABLE(e), p); } return false; }
void XAP_UnixDialog_Image::setWidthEntry(void) { g_signal_handler_block(G_OBJECT(m_wWidthEntry), m_iWidthID); int pos = gtk_editable_get_position(GTK_EDITABLE(m_wWidthEntry)); gtk_entry_set_text( GTK_ENTRY(m_wWidthEntry),getWidthString() ); gtk_editable_set_position(GTK_EDITABLE(m_wWidthEntry), pos); g_signal_handler_unblock(G_OBJECT(m_wWidthEntry), m_iWidthID); }
/************************************************************************** Autocompletes the input line with a player or user name. Returns FALSE if there is no string to complete. **************************************************************************/ static bool chatline_autocomplete(GtkEditable *editable) { #define MAX_MATCHES 10 const char *name[MAX_MATCHES]; char buf[MAX_LEN_NAME * MAX_MATCHES]; gint pos; gchar *chars, *p, *prev; int num, i; size_t prefix_len; /* Part 1: get the string to complete. */ pos = gtk_editable_get_position(editable); chars = gtk_editable_get_chars(editable, 0, pos); p = chars + strlen(chars); while ((prev = g_utf8_find_prev_char(chars, p))) { if (!g_unichar_isalnum(g_utf8_get_char(prev))) { break; } p = prev; } /* p points to the start of the last word, or the start of the string. */ prefix_len = g_utf8_strlen(p, -1); if (0 == prefix_len) { /* Empty: nothing to complete, propagate the event. */ g_free(chars); return FALSE; } /* Part 2: compare with player and user names. */ num = check_player_or_user_name(p, name, MAX_MATCHES); if (1 == num) { gtk_editable_delete_text(editable, pos - prefix_len, pos); pos -= prefix_len; gtk_editable_insert_text(editable, name[0], strlen(name[0]), &pos); gtk_editable_set_position(editable, pos); g_free(chars); return TRUE; } else if (num > 1) { if (get_common_prefix(name, num, buf, sizeof(buf)) > prefix_len) { gtk_editable_delete_text(editable, pos - prefix_len, pos); pos -= prefix_len; gtk_editable_insert_text(editable, buf, strlen(buf), &pos); gtk_editable_set_position(editable, pos); } sz_strlcpy(buf, name[0]); for (i = 1; i < num; i++) { cat_snprintf(buf, sizeof(buf), ", %s", name[i]); } /* TRANS: comma-separated list of player/user names for completion */ output_window_printf(ftc_client, _("Suggestions: %s."), buf); } g_free(chars); return TRUE; }
static void color_code_activate(GtkMenuItem *item, gpointer data) { int color = GPOINTER_TO_INT(data); char *code = g_strdup_printf("\003%d", color); int position = gtk_editable_get_position(GTK_EDITABLE(gui.text_entry)); gtk_editable_insert_text(GTK_EDITABLE(gui.text_entry), code, strlen(code), &position); gtk_editable_set_position(GTK_EDITABLE(gui.text_entry), position + strlen(code)); g_free(code); }
static void gdaui_numeric_entry_assume_delete (GdauiEntry *entry, gint virt_start_pos, gint virt_end_pos, gint offset) { GdauiNumericEntry *fentry; GString *string; gchar *otext, *ntext = NULL; gint i, nlen, ndel, olen = 0; gint cursor_pos; fentry = (GdauiNumericEntry*) entry; ndel = virt_end_pos - virt_start_pos; otext = gdaui_entry_get_text (GDAUI_ENTRY (entry)); cursor_pos = gtk_editable_get_position (GTK_EDITABLE (entry)); if (otext) { if ((ndel == 1) && (otext[virt_start_pos] == fentry->priv->decimal_sep) && (fentry->priv->nb_decimals != G_MAXUINT16)) { gtk_editable_set_position (GTK_EDITABLE (entry), cursor_pos - 1); g_free (otext); return; } string = g_string_new (otext); olen = g_utf8_strlen (otext, -1); g_free (otext); g_string_erase (string, virt_start_pos, ndel); } else string = g_string_new (NULL); cursor_pos -= (virt_end_pos - virt_start_pos); /*g_print ("RAW: [%s]", string->str);*/ text_unformat (fentry, string->str, &cursor_pos); /*g_print ("SANITIZED: [%s]", string->str);*/ if (!test_text_validity (fentry, string->str)) { if ((string->str[0] == fentry->priv->decimal_sep) && string->str[1] == 0) ntext = g_strdup (""); g_string_free (string, TRUE); if (!ntext) { /*g_print ("ERROR!\n");*/ return; } } else { ntext = text_reformat (fentry, string->str, &cursor_pos, FALSE); g_string_free (string, TRUE); } /*g_print ("NEW: [%s]\n", ntext);*/ i = offset; nlen = strlen (ntext); gtk_editable_delete_text ((GtkEditable*) entry, offset, olen + offset); gtk_editable_insert_text ((GtkEditable*) entry, ntext, nlen, &i); g_free (ntext); gtk_editable_set_position (GTK_EDITABLE (entry), cursor_pos); }
static void insert_blue (GtkWidget *widget, gpointer data) { int pos; GtkWidget *entry; entry = GTK_WIDGET (data); pos = gtk_editable_get_position (GTK_EDITABLE (entry)); gtk_editable_insert_text (GTK_EDITABLE (entry), "blue book ", strlen ("blue book "), &pos); }
/* * Check if the string at the cursor position is a beginning of a protocol name. * Possible false positives: * "NOT" at the beginning of the display filter editable text. * "NOT" adjacent to another logical operation. (e.g: exp1 AND NOT exp2). **/ static gboolean is_protocol_name_being_typed(GtkWidget *filter_te, int str_len) { unsigned int i; int op_len, cursor_pos; gchar *start; gchar *pos; static const gchar *logic_ops[] = { "!", "not", "||", "or", "&&", "and", "^^", "xor" }; /* If the cursor is located at the beginning of the filter editable text, * then it's _probably_ a protocol name. **/ if(!(cursor_pos = gtk_editable_get_position(GTK_EDITABLE(filter_te)))) return TRUE; start = gtk_editable_get_chars(GTK_EDITABLE(filter_te), 0, (gint) cursor_pos); /* Point to one char before the current string in the filter editable text */ pos = start + (cursor_pos - str_len); /* Walk back through string to find last char which isn't ' ' or '(' */ while(pos > start) { if(*pos != ' ' && *pos != '(') { /* Check if we have one of the logical operations */ for(i = 0; i < (sizeof(logic_ops)/sizeof(logic_ops[0])); i++) { op_len = (int) strlen(logic_ops[i]); if(pos-start+1 < op_len) continue; /* If one of the logical operations is found, then the current string is _probably_ a protocol name */ if(!strncmp(pos-op_len+1, logic_ops[i], op_len)) { g_free (start); return TRUE; } } /* If none of the logical operations was found, then the current string is not a protocol */ g_free (start); return FALSE; } pos--; } /* The "str" preceded only by ' ' or '(' chars, * which means that the str is _probably_ a protocol name. **/ g_free (start); return TRUE; }
bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style ) { if ( m_windowStyle & wxTE_MULTILINE ) { if ( style.IsDefault() ) { // nothing to do return true; } // VERY dirty way to do that - removes the required text and re-adds it // with styling (FIXME) gint l = gtk_text_get_length( GTK_TEXT(m_text) ); wxCHECK_MSG( start >= 0 && end <= l, false, wxT("invalid range in wxTextCtrl::SetStyle") ); gint old_pos = gtk_editable_get_position( GTK_EDITABLE(m_text) ); char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), start, end ); wxString tmp(text,*wxConvCurrent); g_free( text ); gtk_editable_delete_text( GTK_EDITABLE(m_text), start, end ); gtk_editable_set_position( GTK_EDITABLE(m_text), start ); #if wxUSE_UNICODE wxWX2MBbuf buf = tmp.mbc_str(); const char *txt = buf; size_t txtlen = strlen(buf); #else const char *txt = tmp; size_t txtlen = tmp.length(); #endif // use the attributes from style which are set in it and fall back // first to the default style and then to the text control default // colours for the others wxGtkTextInsert(m_text, wxTextAttr::Combine(style, m_defaultStyle, this), txt, txtlen); /* does not seem to help under GTK+ 1.2 !!! gtk_editable_set_position( GTK_EDITABLE(m_text), old_pos ); */ SetInsertionPoint( old_pos ); return true; } // else single line // cannot do this for GTK+'s Entry widget return false; }
static void entry_delete_cb(GtkText *gtktext, gint start, gint end, gpointer d) { gint origpos; origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); check_at(gtktext, start-1); gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos); /* this is to *UNDO* the selection, in case they were holding shift * while hitting backspace. */ }
static gint luaH_entry_set_position(lua_State *L) { widget_t *w = luaH_checkudata(L, 1, &widget_class); gint pos = luaL_checknumber(L, 2); /* lua table indexes start at 1 */ if (pos > 0) pos--; gtk_editable_set_position(GTK_EDITABLE(w->widget), pos); lua_pushnumber(L, gtk_editable_get_position(GTK_EDITABLE(w->widget))); return 1; }
long wxComboBox::GetInsertionPoint() const { GtkEntry *entry = NULL; #ifdef __WXGTK24__ if (!gtk_check_version(2,4,0)) entry = GTK_ENTRY( GTK_BIN(m_widget)->child ); else #endif entry = GTK_ENTRY( GTK_COMBO(m_widget)->entry ); return (long) gtk_editable_get_position(GTK_EDITABLE(entry)); }
void wxComboBox::WriteText(const wxString& value) { wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); GtkWidget *entry = GTK_COMBO(m_widget)->entry; GtkEditable * const edit = GTK_EDITABLE(entry); gtk_editable_delete_selection(edit); gint len = gtk_editable_get_position(edit); gtk_editable_insert_text(edit, wxGTK_CONV(value), -1, &len); gtk_editable_set_position(edit, len); }
static char* gtkListGetCaretPosAttrib(Ihandle* ih) { if (ih->data->has_editbox) { char* str = iupStrGetMemory(50); GtkEntry* entry = (GtkEntry*)iupAttribGet(ih, "_IUPGTK_ENTRY"); int pos = gtk_editable_get_position(GTK_EDITABLE(entry)); sprintf(str, "%d", (int)pos); return str; } else return NULL; }
static void insert_red (GtkWidget *widget, gpointer data) { int pos; GtkWidget *entry; g_print ("in callback, data is: %p\n", data); entry = GTK_WIDGET (data); pos = gtk_editable_get_position (GTK_EDITABLE (entry)); gtk_editable_insert_text (GTK_EDITABLE (entry), "red book ", strlen ("red book "), &pos); }
/** * Retrieve a possible address (or a part) from an entry box. To make life * easier, we only look at the last valid address component; address * completion only works at the last string component in the entry box. * * \param entry Address entry field. * \param start_pos Address of start position of address. * \return Possible address. */ static gchar *get_address_from_edit(GtkEntry *entry, gint *start_pos) { const gchar *edit_text, *p; gint cur_pos; gboolean in_quote = FALSE; gboolean in_bracket = FALSE; gchar *str; edit_text = gtk_entry_get_text(entry); if (edit_text == NULL) return NULL; cur_pos = gtk_editable_get_position(GTK_EDITABLE(entry)); /* scan for a separator. doesn't matter if walk points at null byte. */ for (p = g_utf8_offset_to_pointer(edit_text, cur_pos); p > edit_text; p = g_utf8_prev_char(p)) { if (*p == '"') { in_quote = TRUE; } else if (!in_quote) { if (!in_bracket && *p == ',') { break; } else if (*p == '<') in_bracket = TRUE; else if (*p == '>') in_bracket = FALSE; } } /* have something valid */ if (g_utf8_strlen(p, -1) == 0) return NULL; #define IS_VALID_CHAR(x) \ (g_ascii_isalnum(x) || (x) == '"' || (x) == '<' || (((unsigned char)(x)) > 0x7f)) /* now scan back until we hit a valid character */ for (; *p && !IS_VALID_CHAR(*p); p = g_utf8_next_char(p)) ; #undef IS_VALID_CHAR if (g_utf8_strlen(p, -1) == 0) return NULL; if (start_pos) *start_pos = g_utf8_pointer_to_offset(edit_text, p); str = g_strdup(p); return str; }
static gboolean position_and_selection_are_at_end (GtkEditable *editable) { int end; int start_sel, end_sel; end = get_editable_number_of_chars (editable); if (gtk_editable_get_selection_bounds (editable, &start_sel, &end_sel)) { if (start_sel != end || end_sel != end) { return FALSE; } } return gtk_editable_get_position (editable) == end; }