Re: Problem with address-entry



Here's one attempt (to restore highlighting). It involves a minimal 
`draw' method, which, when an expansion has been found:
  - saves the selection state;
  - sets the selection to the alias text;
  - calls the parent (gtk_entry) draw method, which then highlights the 
alias;
  - restores the real selection state.
It's not pretty, but it seems to work (today!). Of course, it needs 
serious testing.

The attached patch, which is *incremental to* snake-oil, also cleans up 
some declarations that were missed there.
diff -Nur balsa-temp/libbalsa/address-entry.c balsa-addy/libbalsa/address-entry.c
--- balsa-temp/libbalsa/address-entry.c	Thu Jan 31 16:27:17 2002
+++ balsa-addy/libbalsa/address-entry.c	Thu Jan 31 16:26:50 2002
@@ -52,25 +52,25 @@
 static void libbalsa_address_entry_class_init(LibBalsaAddressEntryClass *klass);
 static void libbalsa_address_entry_init(LibBalsaAddressEntry *ab);
 static void libbalsa_address_entry_destroy(GtkObject * object);
+static void libbalsa_address_entry_draw(GtkWidget * widget,
+                                        GdkRectangle * area);
 
 /*
  * Other function prototypes.
  */
-void libbalsa_inputData_free(inputData * data);
-inputData *libbalsa_inputData_new(void);
-emailData *libbalsa_emailData_new(void);
-void libbalsa_emailData_free(emailData *addy);
-static gint libbalsa_address_entry_button_press(GtkWidget *, GdkEventButton *);
+static void libbalsa_inputData_free(inputData * data);
+static inputData *libbalsa_inputData_new(void);
+static emailData *libbalsa_emailData_new(void);
+static void libbalsa_emailData_free(emailData * addy);
+static gint libbalsa_address_entry_button_press(GtkWidget *,
+                                                GdkEventButton *);
 static gint libbalsa_address_entry_key_press(GtkWidget *, GdkEventKey *);
-inputData *libbalsa_address_entry_get_input(LibBalsaAddressEntry *entry);
-void libbalsa_address_entry_set_input(LibBalsaAddressEntry *entry,
-				      inputData *data);
-void libbalsa_address_entry_show(LibBalsaAddressEntry *entry);
-void libbalsa_force_no_match(emailData *);
-void libbalsa_address_entry_clear_match(LibBalsaAddressEntry *);
-void libbalsa_address_entry_set_focus(LibBalsaAddressEntry *, gint);
-gint libbalsa_address_entry_get_focus(LibBalsaAddressEntry *);
-GList *libbalsa_strsplit(const gchar *, gchar);
+static void libbalsa_address_entry_show(LibBalsaAddressEntry * entry);
+static void libbalsa_force_no_match(emailData *);
+static void libbalsa_address_entry_clear_match(LibBalsaAddressEntry *);
+static GList *libbalsa_strsplit(const gchar *, gchar);
+static gint libbalsa_address_entry_focus_out(GtkWidget * widget,
+                                             GdkEventFocus * event);
 
 
 /*
@@ -205,13 +205,13 @@
 
     object_class->destroy = libbalsa_address_entry_destroy;
 
+    gtk_widget_class->draw = libbalsa_address_entry_draw;
     klass->gtk_entry_button_press = gtk_widget_class->button_press_event;
     gtk_widget_class->button_press_event = libbalsa_address_entry_button_press;
     gtk_widget_class->key_press_event = libbalsa_address_entry_key_press;
     gtk_widget_class->focus_out_event = libbalsa_address_entry_focus_out;
 }
 
-
 static void
 libbalsa_address_entry_init(LibBalsaAddressEntry *address_entry)
 {
@@ -307,7 +307,7 @@
  *   results:
  *     Modifies the structure.
  *************************************************************/
-void
+static void
 libbalsa_force_no_match(emailData *addy) {
     g_return_if_fail(addy != NULL);
 
@@ -327,7 +327,7 @@
  *   results:
  *     A new emailData structure.
  *************************************************************/
-emailData *
+static emailData *
 libbalsa_emailData_new(void)
 {
     emailData *tmp;
@@ -351,7 +351,7 @@
  *   results:
  *     None.
  *************************************************************/
-void
+static void
 libbalsa_emailData_free(emailData *addy)
 {
     g_return_if_fail(addy != NULL);
@@ -375,7 +375,7 @@
  *   results:
  *     A newly allocated structure.
  *************************************************************/
-inputData *
+static inputData *
 libbalsa_inputData_new(void)
 {
     inputData *tmp;
@@ -397,7 +397,7 @@
  *   results:
  *     None.
  *************************************************************/
-void
+static void
 libbalsa_inputData_free(inputData * data)
 {
     g_return_if_fail(data != NULL);
@@ -469,7 +469,7 @@
  *     Returns a newly allocated GList* with newly allocated
  *     data inside it.
  *************************************************************/
-GList *
+static GList *
 libbalsa_strsplit(const gchar *str, gchar delimiter)
 {
     GList *glist;
@@ -928,6 +928,43 @@
 }
 
 /*************************************************************
+ * libbalsa_address_entry_draw:
+ *     Draws the entire widget.
+ *
+ *   credits:
+ *     hands over all the work to GTK_WIDGET_CLASS(parent_class)->draw
+ *
+ *   arguments:
+ *     widget: the widget.
+ *     area:   ignored.
+ *
+ *   results:
+ *     None?  Changes the appearance of the widget.
+ *************************************************************/
+static void
+libbalsa_address_entry_draw(GtkWidget * widget, GdkRectangle * area)
+{
+    g_return_if_fail(widget != NULL);
+    g_return_if_fail(LIBBALSA_IS_ADDRESS_ENTRY(widget));
+    g_return_if_fail(area != NULL);
+
+    if (LIBBALSA_ADDRESS_ENTRY(widget)->alias_start_pos == 0
+        && LIBBALSA_ADDRESS_ENTRY(widget)->alias_end_pos == 0)
+        (*GTK_WIDGET_CLASS(parent_class)->draw) (widget, area);
+    else {
+        gint start = GTK_EDITABLE(widget)->selection_start_pos;
+        gint end = GTK_EDITABLE(widget)->selection_end_pos;
+        GTK_EDITABLE(widget)->selection_start_pos =
+            LIBBALSA_ADDRESS_ENTRY(widget)->alias_start_pos;
+        GTK_EDITABLE(widget)->selection_end_pos =
+            LIBBALSA_ADDRESS_ENTRY(widget)->alias_end_pos;
+        (*GTK_WIDGET_CLASS(parent_class)->draw) (widget, area);
+        GTK_EDITABLE(widget)->selection_start_pos = start;
+        GTK_EDITABLE(widget)->selection_end_pos = end;
+    }
+}
+
+/*************************************************************
  * libbalsa_address_entry_button_press:
  *     This gets called when the user clicks a mouse button.
  *
@@ -2080,7 +2117,7 @@
  *       that got written after this function got written,
  *       like libbalsa_make_address_string()
  *************************************************************/
-void
+static void
 libbalsa_address_entry_show(LibBalsaAddressEntry *address_entry)
 {
     GtkEditable *editable;
@@ -2157,7 +2194,8 @@
     gtk_editable_insert_text(editable, show->str, show->len, &tmp_pos);
     gtk_editable_set_position(editable, cursor);
     g_string_free(show, TRUE);
-    gtk_editable_select_region(editable, start, end);
+    editable->selection_start_pos = start;
+    editable->selection_end_pos = end;
 }
 
 
@@ -2171,7 +2209,7 @@
  *   results:
  *     modifies address_entry
  *************************************************************/
-void
+static void
 libbalsa_address_entry_clear_match(LibBalsaAddressEntry *address_entry)
 {
     emailData *addy;
@@ -2245,7 +2283,7 @@
  *   results:
  *     Sets a flag in the widget.
  *************************************************************/
-gint
+static gint
 libbalsa_address_entry_focus_out(GtkWidget *widget, GdkEventFocus *event)
 {
     LibBalsaAddressEntry *address_entry;
diff -Nur balsa-temp/libbalsa/address-entry.h balsa-addy/libbalsa/address-entry.h
--- balsa-temp/libbalsa/address-entry.h	Fri Aug 24 12:27:00 2001
+++ balsa-addy/libbalsa/address-entry.h	Wed Jan 30 16:19:41 2002
@@ -132,7 +132,6 @@
 
 GtkType libbalsa_address_entry_get_type(void);
 GtkWidget *libbalsa_address_entry_new(void);
-gint libbalsa_address_entry_focus_out(GtkWidget *, GdkEventFocus *);
 void libbalsa_address_entry_set_find_match(LibBalsaAddressEntry *, void *);
 void libbalsa_address_entry_set_domain(LibBalsaAddressEntry *, void *);
 void libbalsa_address_entry_clear_to_send(GtkWidget *);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]