File: sp_freeobj.c

package info (click to toggle)
libforms 1.2.3-1.7
  • links: PTS
  • area: main
  • in suites: forky, trixie
  • size: 10,904 kB
  • sloc: ansic: 97,669; sh: 11,156; makefile: 951
file content (211 lines) | stat: -rw-r--r-- 4,704 bytes parent folder | download | duplicates (4)
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
/*
 * 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 <ctype.h>

#include "fd_main.h"
#include "fd_spec.h"
#include "sp_freeobj.h"
#include "spec/freeobj_spec.h"

static char *get_free_handle( FL_OBJECT  * ob,
                              const char * name );

static char ori_handle_name[ 128 ];

static FD_freeobjattrib *fo_attrib;
static FL_OBJECT *curobj;


/***************************************
 ***************************************/

FL_FORM *
freeobj_create_spec_form( void )
{
    if ( ! fo_attrib )
        fo_attrib = create_form_freeobjattrib( );

    return fo_attrib->freeobjattrib;
}


/***************************************
 ***************************************/

void
freeobj_adjust_spec_form( FL_OBJECT * obj )
{
    curobj = obj;

    *ori_handle_name = '\0';
    if ( obj->c_vdata )
        strcpy( ori_handle_name, obj->c_vdata );
}


/***************************************
 ***************************************/

void
freeobj_fill_in_spec_form( FL_OBJECT * obj )
{
    fl_set_input( fo_attrib->hname, get_free_handle( obj, 0 ) );
}


/***************************************
 ***************************************/

void
freeobj_reread_spec_form( FL_OBJECT * obj  FL_UNUSED_ARG )
{
    if ( curobj )
        handler_name_change_cb( fo_attrib->hname, 0 );
}


/***************************************
 ***************************************/

void
freeobj_restore_spec( FL_OBJECT * obj )
{
    fli_safe_free( obj->c_vdata );
    obj->c_vdata = fl_strdup( ori_handle_name );
}


/***************************************
 ***************************************/

void
freeobj_emit_spec_fd_code( FILE      * fp,
                           FL_OBJECT * obj )
{
    if ( obj->c_vdata )
        fprintf( fp, "    handler: %s\n", ( char * ) obj->c_vdata );
}


/***************************************
 ***************************************/

int
noop_handle( FL_OBJECT * obj,
             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( obj->boxtype, obj->x, obj->y, obj->w, obj->h,
                    obj->col1, obj->bw );
        return 0;
    }

    if ( obj->type == FL_INACTIVE_FREE )
        return 0;
    else if ( obj->type == FL_INPUT_FREE )
        return e == FL_KEYPRESS;

    return 1;
}


/***************************************
 ***************************************/

void
handler_name_change_cb( FL_OBJECT * obj,
                        long        data  FL_UNUSED_ARG )
{
    fli_safe_free( curobj->c_vdata );
    curobj->c_vdata = fl_strdup( fl_get_input( obj ) );
}


/* default free object handler name */

#define MAXFREEOBJ 16

/***************************************
 ***************************************/

static char *
get_free_handle( FL_OBJECT  * obj,
                 const char * name )
{
    static int n;
    static char buf[ 1024 ];
    static FL_OBJECT *freeobj[ MAXFREEOBJ ];

    if ( obj->c_vdata )
        strcpy( buf, obj->c_vdata );
    else if ( name && *name )
        sprintf( buf, "freeobj_%s_handle", name );
    else if ( *obj->label )
        sprintf( buf, "freeobj_%s_handle", obj->label );
    else
    {
        int i, k;

        for ( k = -1, i = 0; i < MAXFREEOBJ && k < 0; i++ )
            if ( freeobj[ i ] == obj )
                k = i;

        if ( k < 0 )
        {
            k = ++n;
            freeobj[ k ] = obj;
        }

        sprintf( buf, "freeobj%d_handle", k );
    }

    return buf;
}


#include "spec/freeobj_spec.c"


/*
 * Local variables:
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */