return to first page linux journal archive
keywordscontents

/*	
	xmulti.c -- An XForms Multilingual Hello World Program

   On a "standard" Linux system, this program can be 
   compiled with the command:
   
   gcc -lX11 -lforms -lm xmulti.c -o xmulti
   
   To have access to the XForms routines, we need to
   include the forms header file
*/

#include <forms.h>

/* 
   We create a few global variables that all functions
   have access to
*/

	FL_FORM		*hello_window;
	FL_OBJECT	*english_button;
	FL_OBJECT	*french_button;
	FL_OBJECT	*done_button;
	FL_OBJECT	*display_area;
	

/*
	This function will set the display_area
	to the selected language
*/

void set_language(FL_OBJECT *obj, long arg)
{
	fl_clear_browser(display_area);
	if(arg == 1) fl_addto_browser(display_area, "@cHello World");
	if(arg == 2) fl_addto_browser(display_area, "@cBonjour Le Monde");
}

/*
   Since XForms applications are just standard C, we
   use a normal main() with command line arguments
   (if any) stored in argv.
*/

int main(int argc, char *argv[])
{
	/*
   The first call is to fl_initialize(), which
   sets up XForms and handles relevant command
   line options
	*/

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

	/*
	We create a simple window with three
	buttons and a display area. Note that
	the english_button and the french_button
	are set to call the function set_language()
	*/
	
       	hello_window = fl_bgn_form(FL_UP_BOX, 180, 125);
       	display_area = fl_add_browser(FL_NORMAL_BROWSER,10,10,160,25,"");
    	fl_set_browser_fontsize(display_area,FL_NORMAL_SIZE);
    	fl_addto_browser(display_area,"@cChoose/Choisir");
  	english_button = fl_add_button(FL_NORMAL_BUTTON,10,45,75,30,"English");
  	fl_set_object_callback(english_button, set_language, 1);
  	french_button = fl_add_button(FL_NORMAL_BUTTON,95,45,75,30,"Francais");
  	fl_set_object_callback(french_button, set_language, 2);
	done_button = fl_add_button(FL_NORMAL_BUTTON, 10, 85, 160, 30,"Done"); 
	fl_end_form();
	
	/*
	Now that we've created our window, we
	need to show it.
	*/
	
        fl_show_form(hello_window,FL_PLACE_FREE,FL_FULLBORDER,\
"Push Done to Quit");
	
	/*
	When the Done button is pressed, fl_do_forms() doesn't
	know what to do (the done button has not been assigned to
	call anything), so it returns.
	*/
        fl_do_forms();
	return(0);
}