Re: [gtk-list] formatted entry



Adrian Feiguin wrote:

> i.e, entry for numeric-date-whatever, input.
> This topic has been discused on the list many times. Is anybody working on
> it? I wonder who is interested and if the mantainer of gtkentry can give
> us an advise.
> Regards,
> <ADRIAN>
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null

I have played with this - my concept is to create a subclass of GtkEntry
called GtkValidatedEntry.  The GtkValidated entry is passed a GtkObject
called a GtkValidate which implements the following procedures:

void  (*finalize_value)(struct GtkValidate_ *v, gchar **buf, gint *cursor_pos);
void  (*set_value)(struct GtkValidate_ *v, const void *value, gchar **buf, gint *cur$
void  (*insert_string)(struct GtkValidate_ *v, const gchar *ins, gint ins_len, gint $
void  (*delete_string)(struct GtkValidate_ *v, gint beg_pos, gint end_pos, gchar **b$

Typically you would subclass GtkValidate to provide your own implementations
of the above procedures along with any needed state data for validation.

Since implementing the above two classes,  I've been writing order entry applications and
developing validating entry fields as needed using these classes.  They work reasonably
well but have flaws.  I am also concerned about the need and difficulties in subclassing
GtkValidate.

My intent is to finish up the current applications I'm working on, and then tune the
GtkValidatedEntry code till I like it better.

A needed feature for this to work (well, work the way I want it to...) is the ability to
emphasize the portion of the entered string that is invalid.  I've patched GtkEntry
to allow me to hook into the gtk_entry_draw_text procedure.  Here's the patch.
I'm not happy with this either, but it works well...

I'm not sure any of the above is helpful.  Is there enough info above for anyone to
think about, or am I being too oblique?   I guess I would be curious if this is
a direction anyone would be interested in following...

Blorp,
Kent



*** gtkentry.c
***************
*** 295,302 ****
--- 295,306 ----
    editable_class->get_chars   = gtk_entry_get_chars;
    editable_class->set_selection = gtk_entry_set_selection;
    editable_class->set_position = gtk_entry_set_position_from_editable;
+ 
+   class->entry_draw_text = gtk_entry_draw_text;
  }
  
+ #define GTK_ENTRY_DRAW_TEXT(e)	GTK_ENTRY_CLASS(e->klass)->entry_draw_text(e)
+ 
  static void
  gtk_entry_set_arg (GtkObject      *object,
  		   GtkArg         *arg,
***************
*** 407,413 ****
    editable->selection_end_pos = 0;
  
    if (GTK_WIDGET_DRAWABLE (entry))
!     gtk_entry_draw_text (entry);
  }
  
  void
--- 411,417 ----
    editable->selection_end_pos = 0;
  
    if (GTK_WIDGET_DRAWABLE (entry))
!     GTK_ENTRY_DRAW_TEXT (entry);
  }
  
  void
***************
*** 831,837 ****
    if (GTK_WIDGET_DRAWABLE (widget))
      {
        gtk_widget_draw_focus (widget);
!       gtk_entry_draw_text (GTK_ENTRY (widget));
      }
  }
  
--- 835,841 ----
    if (GTK_WIDGET_DRAWABLE (widget))
      {
        gtk_widget_draw_focus (widget);
!       GTK_ENTRY_DRAW_TEXT (GTK_ENTRY (widget));
      }
  }
  
***************
*** 850,856 ****
    if (widget->window == event->window)
      gtk_widget_draw_focus (widget);
    else if (entry->text_area == event->window)
!     gtk_entry_draw_text (GTK_ENTRY (widget));
  
    return FALSE;
  }
--- 854,860 ----
    if (widget->window == event->window)
      gtk_widget_draw_focus (widget);
    else if (entry->text_area == event->window)
!     GTK_ENTRY_DRAW_TEXT (GTK_ENTRY (widget));
  
    return FALSE;
  }
***************
*** 1524,1530 ****
  
    entry = GTK_ENTRY (data);
    entry->timer = 0;
!   gtk_entry_draw_text (entry);
  
    GDK_THREADS_LEAVE ();
  
--- 1528,1534 ----
  
    entry = GTK_ENTRY (data);
    entry->timer = 0;
!   GTK_ENTRY_DRAW_TEXT (entry);
  
    GDK_THREADS_LEAVE ();
  
*** gtkentry.h
***************
*** 80,85 ****
--- 80,86 ----
  struct _GtkEntryClass
  {
    GtkEditableClass parent_class;
+   void (*entry_draw_text)(GtkEntry *entry);
  };
  
  GtkType    gtk_entry_get_type       		(void);


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