Re: XForms: problem with the input box

gopinath Taget (gopinatht@hotmail.com)
Wed, 09 Sep 1998 09:51:56 PDT

# To subscribers of the xforms list from "gopinath Taget" <gopinatht@hotmail.com> :

hi,
i tried the changes suggested. but the problem persists. i am giving
the codes of inputall_gui.c and inputall.c below. i would like to know
if any changes are to be made.

also in fdesign in the attributes menu when any thing is added to the
object name or callback fields i get messages like.

Invalid C Identifier Specified for Object Name
float_input

i had to manually add the object names in the inputall_gui.fd file to
affect the changes. what do you think is the problem?

thanks in advance
gopi

/* CODE OF inputall_gui.c */

/* Form definition file generated with fdesign. */

#include "forms.h"
#include <stdlib.h>
#include "inputall_gui.h"

FD_input *create_form_input(void)
{
FL_OBJECT *obj;
FD_input *fdui = (FD_input *) fl_calloc(1, sizeof(*fdui));

fdui->input = fl_bgn_form(FL_NO_BOX, 440, 440);
obj = fl_add_box(FL_UP_BOX,0,0,440,440,"");
fdui->norminput = obj =
fl_add_input(FL_NORMAL_INPUT,40,40,340,30,"NormalInput");
fl_set_object_lalign(obj,FL_ALIGN_TOP_LEFT);
fl_set_object_callback(obj,input_cb,0);
fdui->int_input = obj =
fl_add_input(FL_INT_INPUT,40,100,160,30,"IntInput");
fl_set_object_lalign(obj,FL_ALIGN_TOP_LEFT);
fdui->float_input = obj =
fl_add_input(FL_FLOAT_INPUT,230,100,160,30,"FloatInput");
fl_set_object_lalign(obj,FL_ALIGN_TOP_LEFT);
fdui->date_input = obj =
fl_add_input(FL_DATE_INPUT,40,150,160,30,"DateInput");
fl_set_object_lalign(obj,FL_ALIGN_TOP_LEFT);
obj = fl_add_input(FL_SECRET_INPUT,230,150,160,30,"Secretnput");
fl_set_object_lalign(obj,FL_ALIGN_TOP_LEFT);
fdui->multiinput = obj =
fl_add_input(FL_MULTILINE_INPUT,40,210,360,180,"");
fl_set_object_callback(obj,input_cb,0);
fdui->report = obj = fl_add_text(FL_NORMAL_TEXT,30,400,210,30,"");
fl_set_object_lalign(obj,FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
obj = fl_add_button(FL_NORMAL_BUTTON,330,400,70,30,"Done");
fl_set_object_callback(obj,done_cb,0);
obj = fl_add_button(FL_NORMAL_BUTTON,250,400,70,30,"Hide/Show");
fl_set_object_callback(obj,hide_show_cb,0);
fl_end_form();

fdui->input->fdui = fdui;

return fdui;
}
/*---------------------------------------*/

/*CODE OF inputall.c */

/*
* Show all the input field types
*
* This file is part of xforms package.
* T.C. Zhao and M. Overmars, 1997
*/
#include "forms.h"
#include "inputall_gui.h"
#include <stdlib.h>

int input_posthandler( FL_OBJECT *obj, int event, FL_Coord mx, FL_Coord
my,
int key, void *xevent )

{

const char *current_text = fl_get_input( obj );
int l_current_text = strlen( current_text );
int textwidth = fl_get_string_width( obj->lstyle, obj->lsize,
current_text, l_current_text );

if ( textwidth > obj->w ) {

int xpos;
int ypos;
int xoffset;

fl_get_input_cursorpos( obj, &xpos, &ypos );

xoffset = fl_get_string_width( obj->lstyle, obj->lsize,
current_text, xpos );
if ( xoffset < fl_get_input_xoffset( obj ) )
fl_set_input_xoffset( obj, xoffset );

}
return !FL_PREEMPT;

}

/* callbacks for form input */
void done_cb(FL_OBJECT *ob, long data)
{
fl_finish();
exit(0);
}

void input_cb(FL_OBJECT *ob, long data)
{
int cx, cy, pos;
char buf[128];

pos = fl_get_input_cursorpos(ob, &cx,&cy);
sprintf(buf,"x=%d y=%d",cx, cy);
fl_set_object_label(((FD_input *)ob->form->fdui)->report,buf);
}

void hide_show_cb(FL_OBJECT *ob, long data)
{
FD_input *fd = ob->form->fdui;

if(fd->multiinput->visible)
fl_hide_object(fd->multiinput);
else
fl_show_object(fd->multiinput);
}

int main(int argc, char *argv[])
{
FD_input *fd_input;

fl_initialize(&argc, argv, 0, 0, 0);
fd_input = create_form_input();

/* fill-in form initialization code */
fl_set_object_dblbuffer(fd_input->report,1);
fl_set_object_return(fd_input->multiinput,FL_RETURN_ALWAYS);
fl_set_object_return(fd_input->norminput,FL_RETURN_ALWAYS);

/* show the first form */

fl_set_object_posthandler( fd_input->norminput, input_posthandler );
fl_set_object_posthandler( fd_input->int_input, input_posthandler );
fl_set_object_posthandler( fd_input->float_input, input_posthandler
);
fl_set_object_posthandler( fd_input->date_input, input_posthandler );

fl_show_form(fd_input->input,FL_PLACE_CENTERFREE,FL_FULLBORDER,"input");

while (fl_do_forms())
;
return 0;
}

#include "inputall_gui.c"

>
>I just took a minute to look at the inputall.c source. Part of the
>problem is that not all of the objects are named, so you don't have
>access to them in the FD_input data structure. You can fix this by
>`cd'ing to the fd subdirectory in DEMOS and pulling `inputall_gui.fd'
>into `fdesign'. Add names for the Input objects which do not have
>names -- I chose `int_input', `float_input', and `date_input',
>respectively (ignoring the FL_SECRET_INPUT, since it doesn't print on
>the screen, anyhow). After saving the new GUI file, I added
>
> fl_set_object_posthandler( fd_input->norminput, input_posthandler );
> fl_set_object_posthandler( fd_input->int_input, input_posthandler );
> fl_set_object_posthandler( fd_input->float_input, input_posthandler
);
> fl_set_object_posthandler( fd_input->date_input, input_posthandler
);
>
>to `inputall.c' right before the call to fl_show_form(), added the
>input_posthandler() code, compile, and linked.
>
>It worked as expected.
>
> spl
>_________________________________________________
>To unsubscribe, send the message "unsubscribe" to
>xforms-request@bob.usuf2.usuhs.mil or see
>http://bob.usuf2.usuhs.mil/mailserv/xforms.html
>XForms Home Page: http://bragg.phys.uwm.edu/xforms
>List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/
>
>

______________________________________________________
Get Your Private, Free Email at /cgi-bin/exit-to?http://www.hotmail.com
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/