;;; -*-Scheme-*-

(define-widget-type 'ascii "AsciiText.h"

"static SYMDESCR Edittype_Syms[] = {
    { \"text-read\",     XttextRead },
    { \"text-append\",   XttextAppend },
    { \"text-edit\",     XttextEdit },
    { 0, 0 }
};
static SYMDESCR Options_Syms[] = {
    { \"word-break\",         wordBreak },
    { \"scroll-vertical\",    scrollVertical },
    { \"scroll-horizontal\",  scrollHorizontal },
    { \"scroll-on-overflow\", scrollOnOverflow },
    { \"resize-width\",       resizeWidth },
    { \"resize-height\",      resizeHeight },
    { \"editable\",           editable },
    { 0, 0 }
};")

(define-widget-class 'ascii-string 'asciiStringWidgetClass
  '(font Font FontStruct)
  '(foreground Foreground Pixel)
  '(editType EditType EditMode)
  '(length Length Int))

(define-widget-class 'ascii-disk 'asciiDiskWidgetClass
  '(font Font FontStruct)
  '(foreground Foreground Pixel)
  '(editType EditType EditMode))

(define scheme->edit-type
"   return (XtArgVal)Symbols_To_Bits (x, 0, Edittype_Syms);")

(scheme->c 'ascii-string-editType scheme->edit-type)
(scheme->c 'ascii-disk-editType   scheme->edit-type)

(define scheme->text-options
"   return (XtArgVal)Symbols_To_Bits (x, 1, Options_Syms);")

(scheme->c 'ascii-string-textOptions scheme->text-options)
(scheme->c 'ascii-disk-textOptions   scheme->text-options)

(define text-options->scheme
"   return Bits_To_Symbols ((unsigned long)x, 1, Options_Syms);")

(c->scheme 'ascii-string-textOptions text-options->scheme)
(c->scheme 'ascii-disk-textOptions   text-options->scheme)

(scheme->c 'ascii-string-string
"   char *s, *t;
    Make_C_String (x, t);
    if ((s = XtMalloc (1024)) == 0)
	Primitive_Error (\"out of memory\");
    strncpy (s, t, 1024);
    return (XtArgVal)s;")

(scheme->c 'ascii-string-length
"   if (Get_Integer (x) > 1024)
	Primitive_Error (\"invalid length for ascii-string\");
    return (XtArgVal)Get_Integer (x);")
