1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
* This file is part of XForms.
*
* XForms is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1, or
* (at your option) any later version.
*
* XForms is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with XForms; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
/*
* This demo shows the use of a browser and a file selector.
* Good browser/scrollbar test
*
* This file is part of xforms package
* T.C. Zhao and M. Overmars
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "include/forms.h"
typedef struct {
FL_FORM * form;
void * vdata;
char * cdata;
long ldata;
FL_OBJECT * br;
} FD_form;
/***************************************
***************************************/
void
load_file( FL_OBJECT * ob,
long arg FL_UNUSED_ARG )
{
const char *fname;
FD_form *fdui = ob->form->fdui;
if ( ( fname = fl_show_file_selector( "File To Load", "", "*", "" ) ) )
{
if ( ! fl_load_browser( fdui->br, fname ) )
fl_add_browser_line( fdui->br,"NO SUCH FILE!" );
}
}
/***************************************
***************************************/
void
set_size( FL_OBJECT * ob,
long arg)
{
FD_form *fdui = ob->form->fdui;
fl_set_browser_fontsize( fdui->br, arg );
}
/***************************************
***************************************/
void
exit_program( FL_OBJECT * ob FL_UNUSED_ARG,
long data FL_UNUSED_ARG )
{
fl_finish( );
exit( 0 );
}
/***************************************
***************************************/
void
hide_show( FL_OBJECT * ob,
long data FL_UNUSED_ARG )
{
FD_form *fdui = ob->form->fdui;
if ( fl_object_is_visible( fdui->br ) )
fl_hide_object( fdui->br );
else
fl_show_object( fdui->br );
}
/***************************************
***************************************/
FD_form *
create_form( void )
{
FL_OBJECT *obj;
FL_Coord x = 20,
dx = 80,
dy = 28;
FD_form *fdui = fl_calloc( 1, sizeof *fdui );
fdui->form = fl_bgn_form( FL_NO_BOX, 590, 610 );
obj = fl_add_box( FL_UP_BOX, 0, 0, 590, 610, "" );
fdui->br = obj = fl_add_browser( FL_NORMAL_BROWSER, 20, 20, 550, 530, "" );
/* fl_set_object_boxtype( obj, FL_EMBOSSED_BOX ); */
obj = fl_add_button( FL_NORMAL_BUTTON, x, 565, dx-5, dy, "Load" );
fl_set_object_callback( obj, load_file, 0 );
x += dx ;
obj = fl_add_lightbutton( FL_RADIO_BUTTON, x, 565, dx, dy, "Tiny" );
fl_set_object_callback( obj, set_size, FL_TINY_SIZE );
x += dx;
obj = fl_add_lightbutton( FL_RADIO_BUTTON, x , 565, dx, dy, "Small" );
fl_set_object_callback( obj, set_size, FL_SMALL_SIZE );
fl_set_button( obj, FL_SMALL_SIZE == FL_BROWSER_FONTSIZE );
x += dx;
obj = fl_add_lightbutton( FL_RADIO_BUTTON, x , 565, dx, dy, "Normal" );
fl_set_object_callback( obj, set_size, FL_NORMAL_SIZE );
fl_set_button( obj, FL_NORMAL_SIZE == FL_BROWSER_FONTSIZE );
x += dx;
obj = fl_add_lightbutton( FL_RADIO_BUTTON, x , 565, dx, dy, "Large" );
fl_set_object_callback( obj, set_size, FL_LARGE_SIZE );
x += dx + 4;
obj = fl_add_button( FL_NORMAL_BUTTON, x, 565, dx, dy, "Hide/Show" );
fl_set_object_callback( obj, hide_show, 0 );
x += dx + 5;
obj = fl_add_button( FL_NORMAL_BUTTON, x, 565, 60, dy, "Exit" );
fl_set_object_callback( obj, exit_program, 0 );
fl_end_form();
fl_adjust_form_size( fdui->form );
fdui->form->fdui = fdui;
return fdui;
}
/***************************************
***************************************/
int
main( int argc,
char * argv[ ] )
{
FD_form *fdui;
FL_OBJECT *o;
fl_initialize( &argc, argv, "FormDemo", 0, 0 );
fdui = create_form( );
fl_clear_browser( fdui->br );
fl_add_browser_line( fdui->br, "LOAD A FILE." );
fl_set_browser_fontstyle( fdui->br,FL_FIXED_STYLE );
fl_show_form( fdui->form, FL_PLACE_FREE, FL_FULLBORDER, "Browser" );
o = fl_do_forms( );
fprintf( stderr, "%p %d %s\n", o, o->objclass, o->label ? o->label: "" );
fl_hide_form( fdui->form );
fl_free_form( fdui->form );
fl_finish( );
return 0;
}
|