Re: XForms: Widgets and XForms

Kay Fleetwood (rfleetwood@tecmasters.com)
Fri, 06 Nov 1998 10:15:21 +0000

# To subscribers of the xforms list from Kay Fleetwood <rfleetwood@tecmasters.com> :

--------------3A4AF3FA13A090C57125B2B5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Joao Filipe Ferreira wrote:

> # To subscribers of the xforms list from Joao Filipe Ferreira <jfilipe@alumni.dee.uc.pt> :
>
> Ok. Another problem has revieled itself... How does one use widgets with
> XForms? The picture magnifying procedings use an Athena widget called
> Scale and I would like to insert the image it produces into a canvas
> object - what should I do?
>
> I already have the postscript manual and the (UPDATED - that was the
> whole problem) online manual's address and half of my wories are over, so
> shoot! I'm ready for all the info you can throw at me! ;)
>
> Thanking you all
> (for past and, perhaps, future answers),
> JFC
>
>

The following are code fragments from an application I have been working on for the past 9
months. I too had a widget I needed to insert into my xforms program. By searching through
the archives, I came across someone who had done some of the same. The only reason I mention
this, is that without his help and sample code, I could not have accomplished my goal. So a
big thanks to you, Dr. Anthony Symons!

Well, here goes.... (the faint of heart should probably not read any further) and I hope it
helps.

#include ...

/* forms declared */

XtAppContext app;
Widget toplevel;
Widget map_form;
Widget map_widget;

int main(int argc, char *argv[])
{
Screen* scr;
long wid, hght;
Arg args[2];

/* set the application context */
toplevel = XtVaAppInitialize (&app, app_name, NULL, 0,
&argc, argv, NULL, NULL);

scr = XtScreen(toplevel);
wid = WidthOfScreen(scr);
hght = HeightOfScreen(scr);
XtSetArg(args[0], XtNheight, (XtArgVal)hght);
XtSetArg(args[1], XtNwidth, (XtArgVal)wid);
XtSetValues(toplevel, args, 2);

XtRealizeWidget(toplevel);

fl_initialize(&argc, argv, 0, 0, 0);

fl_display = XtDisplay(toplevel);

fl_set_event_callback (tmi_XtEventHandler, NULL);

/* forms created */

/* set the application's main form */
fl_set_app_mainform(fd_FMain->FMain);

fl_do_forms();

return 0;
}

/***************************************************************/
/* tmi_XtEventHandle */
/***************************************************************/
int tmi_XtEventHandler(XEvent* xev, void* data)
{
XtDispatchEvent(xev);
return (TRUE);
}

/***************************************************************/
/* ShowMapForm */
/***************************************************************/
void ShowMapForm(/* any thing needed to pass in */)
{
/*
initialize the form before it is shown
*/
static int initialized = 0;
int success;
Window win;

/* check if the form has already been initialized */
if (!initialized)
{
map_form = NULL;
map_widget = NULL;

/* show the form */
fl_show_form(fd_FMap->FMap...);

/* initialize the map widget */
/* the widget is displayed in an xt form and then
the form is placed in the canvas on an xforms form
(get's a little confusing here....be careful)
*/
CreateMapDisplay(&app, &map_form, &map_widget);

/* i have to do this periodically to let everything
(the display, memory releasing) catch up
*/
fl_msleep(500);

win = XtWindow(map_form);

/* this is where you insert the widget into the gl
canvas....a member of our team (Carl) created an
object (a mapframe) that does it all for me
(has scroll bars too...a few quirks but really neat)
*/
/* this would be the point where steve says it gets
really hairy
*/
tmi_set_mapframe_window(fd_FMap->frmMapDisplay, win);

initialized = 1;

}

fl_raise_form(fd_FMap->FMap);

/* lots more map stuff here */

fl_msleep(1000);

}

/***************************************************************/
/* CreateMapDisplay */
/***************************************************************/
void CreateMapDisplay(XtAppContext* app_context,
Widget* form, Widget* map)
{
int i,success;
char* array[2] = {"app_name", NULL};
long h,w;
Arg form_args[5];
Arg map_args[7];

h = ..canvas's height..;

w = ..canvas's width..;

/* args to set up the xt form and map widget */
i = 0;
XtSetArg(form_args[i], XtNheight, (XtArgVal)h); i++;
XtSetArg(form_args[i], XtNwidth, (XtArgVal)w); i++;
XtSetArg(form_args[i], XtNborderWidth, (XtArgVal)2); i++;
XtSetArg(form_args[i], XtNbackground, (XtArgVal)FL_COL1);i++;
XtSetArg(form_args[i], XtNforeground, (XtArgVal)FL_WHITE);

i = 0;
XtSetArg(map_args[i], XtNheight, (XtArgVal)h); i++;
XtSetArg(map_args[i], XtNwidth, (XtArgVal)w); i++;
XtSetArg(map_args[i], XtNbackground, (XtArgVal)FL_WHITE); i++;
XtSetArg(map_args[i], XtNforeground, (XtArgVal)FL_COL1); i++;
XtSetArg(map_args[i], XatNperipheryOn, TRUE); i++;
XtSetArg(map_args[i], XatNperipheryColor, FL_BLACK); i++;
XtSetArg(map_args[i], XtNborderWidth, 0);

*form = XtCreatePopupShell("", shellWidgetClass,
toplevel, form_args, XtNumber(form_args));

/* stuff specific to my map */

/* at this point we have the widgets */
XtSetValues(*map, map_args, XtNumber(map_args));

if (!XtIsRealized(*form))
{
/* realize it */
XtRealizeWidget(*form);
}

}

Don't forget to include the -lXt in your compilation.

Good luck!

--
Kay Fleetwood
------------------------------------
Tec-Masters, Inc.
Advanced Studies and Research Center
2800 W. Gore
N. Shepler, Suite 500
Lawton, OK  73505-6377
Email:  rfleetwood@tecmasters.com

--------------3A4AF3FA13A090C57125B2B5 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit

Joao Filipe Ferreira wrote:

# To subscribers of the xforms list from Joao Filipe Ferreira <jfilipe@alumni.dee.uc.pt> :

 Ok. Another problem has revieled itself... How does one use widgets with
XForms? The picture magnifying procedings use an Athena widget called
Scale and I would like to insert the image it produces into a canvas
object - what should I do?

 I already have the postscript manual and the (UPDATED - that was the
whole problem) online manual's address and half of my wories are over, so
shoot! I'm ready for all the info you can throw at me! ;)

                                                Thanking you all
                                (for past and, perhaps, future answers),
                                                        JFC
 
 

The following are code fragments from an application I have been working on for the past 9 months.  I too had a widget I needed to insert into my xforms program.  By searching through the archives, I came across someone who had done some of the same.  The only reason I mention this, is that without his help and sample code, I could not have accomplished my goal.  So a big thanks to you, Dr. Anthony Symons!

Well, here goes.... (the faint of heart should probably not read any further) and I hope it helps.
 

#include ...


/* forms declared */
XtAppContext app;
Widget toplevel;
Widget map_form;
Widget map_widget;

int main(int argc, char *argv[])
{
        Screen* scr;
        long wid, hght;
        Arg args[2];
        

        /* set the application context                             */
        toplevel = XtVaAppInitialize (&app, app_name, NULL, 0,
                &argc, argv, NULL, NULL);
                
        scr = XtScreen(toplevel);
        wid = WidthOfScreen(scr);
        hght = HeightOfScreen(scr);
        XtSetArg(args[0], XtNheight, (XtArgVal)hght);
        XtSetArg(args[1], XtNwidth, (XtArgVal)wid);
        XtSetValues(toplevel, args, 2);
        
        XtRealizeWidget(toplevel);
                
        
        fl_initialize(&argc, argv, 0, 0, 0);
        
        fl_display = XtDisplay(toplevel);
        
        fl_set_event_callback (tmi_XtEventHandler, NULL);
        
        /* forms created */
        
        /* set the application's main form                         */
        fl_set_app_mainform(fd_FMain->FMain);
        

        fl_do_forms();
        
        return 0;
}


/***************************************************************/
/*                      tmi_XtEventHandle                      */
/***************************************************************/
int tmi_XtEventHandler(XEvent* xev, void* data)
{
        XtDispatchEvent(xev);
        return (TRUE);
}



/***************************************************************/
/*                       ShowMapForm                           */
/***************************************************************/
void ShowMapForm(/* any thing needed to pass in */)
{
/*
        initialize the form before it is shown
*/      
        static int initialized = 0;
        int success;
        Window win;
        
        
        /* check if the form has already been initialized          */
        if (!initialized)
        {
                map_form = NULL;
                map_widget = NULL;
                
                /* show the form                                       */
                fl_show_form(fd_FMap->FMap...);
                
        
                /* initialize the map widget                           */
                /* the widget is displayed in an xt form and then
                        the form is placed in the canvas on an xforms form
                        (get's a little confusing here....be careful)
                */
                CreateMapDisplay(&app, &map_form, &map_widget);
                
                /* i have to do this periodically to let everything
                        (the display, memory releasing) catch up
                */
                fl_msleep(500);
                
                
                win = XtWindow(map_form);
                
                
                /* this is where you insert the widget into the gl
                        canvas....a member of our team (Carl) created an 
                        object (a mapframe) that does it all for me 
                        (has scroll bars too...a few quirks but really neat)
                */
                /* this would be the point where steve says it gets
                        really hairy
                */
                tmi_set_mapframe_window(fd_FMap->frmMapDisplay, win);
                
                initialized = 1;
                
        }
        
        fl_raise_form(fd_FMap->FMap);

        
        /* lots more map stuff here                                */
                
        
        fl_msleep(1000);
        
}


/***************************************************************/
/*                       CreateMapDisplay                      */
/***************************************************************/
void CreateMapDisplay(XtAppContext* app_context, 
                                                                Widget* form, Widget* map)
{
        int i,success;
        char* array[2] = {"app_name", NULL};
        long h,w;
        Arg form_args[5];
        Arg map_args[7];
        
        h = ..canvas's height..;
        
        w = ..canvas's width..;
        
        /* args to set up the xt form and map widget               */
        i = 0;
        XtSetArg(form_args[i], XtNheight, (XtArgVal)h); i++;
        XtSetArg(form_args[i], XtNwidth, (XtArgVal)w); i++;
        XtSetArg(form_args[i], XtNborderWidth, (XtArgVal)2); i++;
        XtSetArg(form_args[i], XtNbackground, (XtArgVal)FL_COL1);i++;
        XtSetArg(form_args[i], XtNforeground, (XtArgVal)FL_WHITE);
        
        i = 0;
        XtSetArg(map_args[i], XtNheight, (XtArgVal)h); i++;
        XtSetArg(map_args[i], XtNwidth, (XtArgVal)w); i++;
        XtSetArg(map_args[i], XtNbackground, (XtArgVal)FL_WHITE); i++;
        XtSetArg(map_args[i], XtNforeground, (XtArgVal)FL_COL1); i++;
        XtSetArg(map_args[i], XatNperipheryOn, TRUE); i++;
        XtSetArg(map_args[i], XatNperipheryColor, FL_BLACK); i++;
        XtSetArg(map_args[i], XtNborderWidth, 0);
        
        *form = XtCreatePopupShell("", shellWidgetClass,
                                toplevel, form_args, XtNumber(form_args));
        
        /* stuff specific to my map */
        
        /* at this point we have the widgets                       */
        XtSetValues(*map, map_args, XtNumber(map_args));
        
        
        if (!XtIsRealized(*form))
        {
                /* realize it */
                XtRealizeWidget(*form);
        }

        
}


Don't forget to include the -lXt in your compilation.
Good luck!
-- 
Kay Fleetwood
------------------------------------
Tec-Masters, Inc.
Advanced Studies and Research Center
2800 W. Gore
N. Shepler, Suite 500
Lawton, OK  73505-6377
Email:  rfleetwood@tecmasters.com
  --------------3A4AF3FA13A090C57125B2B5-- _________________________________________________ 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/