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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
/*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file sp_freeobj.c
*
* This file is part of XForms package
* Copyright (c) 1996-2002 T.C. Zhao and Mark Overmars
* All rights reserved.
*
* Settting free object class specific attributes, in this
* case, the handler name. We store this piece of into
* in ob->c_vdata;
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "include/forms.h"
#include "fd_main.h"
#include "fd_spec.h"
#include <ctype.h>
#include "spec/freeobj_spec.h"
static char *get_free_handle( FL_OBJECT * ob,
const char * name );
static char ori_handle_name[ 128 ];
extern FD_freeobjattrib *create_form_freeobjattrib( void );
static FD_freeobjattrib *fo_attrib;
static SuperSPEC *freeobj_spec;
static void show_spec( SuperSPEC * );
static FL_OBJECT *edited;
/***************************************
***************************************/
void *
get_freeobj_spec_fdform( void )
{
if ( ! fo_attrib )
fo_attrib = create_form_freeobjattrib( );
return fo_attrib;
}
/***************************************
***************************************/
void
freeobj_spec_restore( FL_OBJECT * ob,
long data FL_UNUSED_ARG )
{
if ( ob->c_vdata )
fl_free( ob->c_vdata );
ob->c_vdata = fl_strdup( ori_handle_name );
}
/***************************************
***************************************/
static void
show_spec( SuperSPEC * spec FL_UNUSED_ARG )
{
fl_set_input( fo_attrib->hname, get_free_handle( edited, 0 ) );
}
/***************************************
***************************************/
int
set_freeobj_attrib( FL_OBJECT * ob )
{
fo_attrib->vdata = edited = ob;
*ori_handle_name = '\0';
if ( ob->c_vdata )
strcpy( ori_handle_name, ob->c_vdata );
show_spec( freeobj_spec );
return 0;
}
/***************************************
***************************************/
int
noop_handle( FL_OBJECT * ob,
int e,
FL_Coord mx FL_UNUSED_ARG,
FL_Coord my FL_UNUSED_ARG,
int k FL_UNUSED_ARG,
void * xev FL_UNUSED_ARG )
{
if ( e == FL_DRAW )
{
fl_drw_box( ob->boxtype, ob->x, ob->y, ob->w, ob->h, ob->col1, ob->bw );
return 0;
}
if ( ob->type == FL_INACTIVE_FREE )
return 0;
if ( ob->type == FL_INPUT_FREE )
return e == FL_KEYPRESS;
return 1;
}
/***************************************
***************************************/
#if 0
static FL_OBJECT *
create_a_freeobj( FL_OBJECT * ob )
{
FL_OBJECT *defobj = 0;
defobj = fl_create_free( ob->type, ob->x, ob->y, ob->w, ob->h,
ob->label, noop_handle );
return defobj;
}
#endif
/***************************************
***************************************/
void
emit_freeobj_code( FILE * fp FL_UNUSED_ARG,
FL_OBJECT * ob FL_UNUSED_ARG )
{
}
/***************************************
***************************************/
void
save_freeobj_attrib( FILE * fp,
FL_OBJECT * ob )
{
if ( ob->c_vdata )
fprintf( fp, " handler: %s\n", ( char * ) ob->c_vdata );
}
/***************************************
***************************************/
void
handler_name_change_cb( FL_OBJECT * ob,
long data FL_UNUSED_ARG )
{
edited->c_vdata = fl_strdup( fl_get_input( ob ) );
}
/* default free object handler name */
#define MAXFREEOBJ 16
/***************************************
***************************************/
static char *
get_free_handle( FL_OBJECT * ob,
const char * name )
{
static int n;
static char buf[ 1024 ];
static FL_OBJECT *freeobj[ MAXFREEOBJ ];
int i, k;
if ( ob->c_vdata )
strcpy( buf, ob->c_vdata );
else if ( name && *name )
sprintf( buf, "freeobj_%s_handle", name );
else if ( *ob->label )
sprintf( buf, "freeobj_%s_handle", ob->label );
else
{
for ( k = -1, i = 0; i < MAXFREEOBJ && k < 0; i++ )
if ( freeobj[ i ] == ob )
k = i;
if ( k < 0 )
{
k = ++n;
freeobj[ k ] = ob;
}
sprintf( buf, "freeobj%d_handle", k );
}
return buf;
}
#include "spec/freeobj_spec.c"
/*
* Local variables:
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
|