[AD] Filtered d_edit_proc() patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


The attached patch modifies d_edit_proc() so that you
can create fields that only accept numbers, capital
letters, etc. To do so, just write a filter callback
and set a pointer to it in the edit proc's dp2 field.
The function is of the form:
   int edit_callback(int c, void *dp3);
and it will be called anytime you enter a character.
The c parameter will contain a copy of the character,
and it can return the character unchanged, pass zero
to cause the character to be ignored, or return a
modified value (similar to the keyboard callbacks).
(The patch also adds this usage information to the
comment preceding d_edit_proc()'s code.)
The patch was created from the guiproc.c file in the
normal Allegro 4.1.18 WIP distribution.



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 
--- guiproc.old.c	2004-12-30 10:21:24.000000000 +0000
+++ guiproc.new.c	2005-02-20 00:12:32.000000000 +0000
@@ -636,6 +636,16 @@
  *  can be typed into this object. The d1 field specifies the maximum
  *  number of characters that it will accept, and d2 is the text cursor 
  *  position within the string.
+ *  The dp2 field may be set to an optional filter callback, which (if
+ *  present) will be called anytime a character is entered. This callback
+ *  should have the prototype:
+ *
+ *  int edit_callback(int c, void *dp3);
+ *
+ *  It will be passed a copy of the character about to be added to the
+ *  string, and can either return the character unmodified, return zero to
+ *  cause the key to be ignored, or return a modified value to change what
+ *  will be added to the string.
  */
 int d_edit_proc(int msg, DIALOG *d, int c)
 {
@@ -645,6 +655,7 @@
    int f, l, p, w, x, fg, b, scroll;
    char buf[16];
    char *s, *t;
+   int (*proc)(int c, void *dp3);
    ASSERT(d);
    
    gui_bmp = gui_get_screen();
@@ -810,6 +821,10 @@
 	 return D_USED_CHAR;
 
       case MSG_UCHAR:
+	 if (d->dp2) {
+	    proc = d->dp2;
+	    c = (*proc)(c, d->dp3);
+	 }
 	 if ((c >= ' ') && (uisok(c)) && (!ignore_next_uchar)) {
 	    if (l < d->d1) {
 	       uinsert(s, d->d2, c);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/