File: fd_groups.c

package info (click to toggle)
libforms 1.0.93sp1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,548 kB
  • ctags: 9,107
  • sloc: ansic: 97,227; sh: 9,236; makefile: 858
file content (214 lines) | stat: -rw-r--r-- 5,618 bytes parent folder | download | duplicates (2)
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
/*
 * 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 fd_groups.c
 *
 *  This file is part of XForms package
 *  Copyright (c) 1996-2002  T.C. Zhao and Mark Overmars
 *  All rights reserved.
 *
 * This file is part of the Form Designer.
 *
 * It maintains a list of groups in the form. Each group can be
 * assigned a name.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "include/forms.h"
#include "fd_main.h"
#include "fd/ui_theforms.h"


/**** Data Structure maintaining groups in current form ****/

static FL_OBJECT **begobj = NULL;     /* Begin objects of the groups */


/**** Call-back routines ****/


/***************************************
 * Sets the current group in the form
 ***************************************/

void
group_cb( FL_OBJECT * obj  FL_UNUSED_ARG,
          long        arg  FL_UNUSED_ARG )
{
    int nn = fl_get_browser( fd_control->groupbrowser );

    if ( nn > 0 )
        addgroupto_selection( begobj[ nn ] );
    else if ( nn < 0 )
        deletegroupfrom_selection( begobj[ -nn ] );
    redraw_the_form( 0 );
}


/***************************************
 * Changes the name of the current group
 ***************************************/

void
changegroupname_cb( FL_OBJECT * obj  FL_UNUSED_ARG,
                    long        arg  FL_UNUSED_ARG )
{
    char name[ MAX_VAR_LEN ],
         cbname[ MAX_VAR_LEN ],
         argname[ MAX_VAR_LEN ];
    int i,
        numb = 0;
    const char *s;
    const char *sp;

    if ( cur_form == NULL )
        return;

    for ( i = 1; i <= fl_get_browser_maxline( fd_control->groupbrowser ); i++ )
        if ( fl_isselected_browser_line( fd_control->groupbrowser, i ) )
        {
            if ( numb != 0 )
            {
                fl_show_messages( "Cannot change name of multiple groups" );
                return;
            }
            numb = i;
        }

    if ( numb == 0 )
    {
        fl_show_messages( "No group is selected" );
        return;
    }

    get_object_name( begobj[ numb ], name, cbname, argname );

 get_changed_group_name:

    if (    ! ( s = fl_show_input( "Enter group name (must be usable as "
                                   "a C variable):", name ) )
         || ! *s )
        return;

    if (    ! isascii( ( unsigned char ) *s )
         || ! ( isalpha( ( unsigned char ) *s ) || *s == '_' ) )
    {
        fl_show_alert( "Error", "Invalid C identifier specified for group "
                       "name:", s, 0 );
        goto get_changed_group_name;
    }

    for ( sp = s + 1; *sp; sp++ )
        if (    ! isascii( ( unsigned char ) *sp )
             || ! ( isalnum( ( unsigned char ) *sp ) || *sp == '_' ) )
        {
            fl_show_alert( "Error", "Invalid C identifier specified for group "
                           "name:", s, 0 );
            goto get_changed_group_name;
        }

    strcpy( name, s );
    set_object_name( begobj[ numb ], name, cbname, argname );
    fillin_groups( );
    changed = 1;
}


/***************************************
 * Fills in the current list of groups
 ***************************************/

void
fillin_groups( void )
{
    char name[ MAX_VAR_LEN ],
         cbname[ MAX_VAR_LEN ],
         argname[ MAX_VAR_LEN ];
    FL_OBJECT *obj,
              *obj2;
    int i;

    if ( cur_form == NULL )
    {
        fl_clear_browser( fd_control->groupbrowser );
        return;
    }

    fl_freeze_form( fd_control->groupbrowser->form );
    fl_clear_browser( fd_control->groupbrowser );

    /* Check whether groups are empty. */

    obj = cur_form->first;
    while ( obj != NULL )
    {
        obj2 = obj;
        obj = obj->next;
        if (    obj2->objclass == FL_END_GROUP
             && obj2->prev != NULL
             && obj2->prev->objclass == FL_BEGIN_GROUP )
        {
            fl_delete_object( obj2->prev );
            fl_delete_object( obj2 );
        }
    }

    /* Put the still existing groups in the list */

    for ( i = 0, obj = cur_form->first; obj; obj = obj->next )
        if ( obj->objclass == FL_BEGIN_GROUP )
            i++;

    if ( i > 0 )
    {
        begobj = fl_realloc( begobj, ( i + 1 ) * sizeof *begobj );

        for ( i = 1, obj = cur_form->first; obj; obj = obj->next )
            if ( obj->objclass == FL_BEGIN_GROUP )
            {
                begobj[ i ] = obj;
                get_object_name( obj, name, cbname, argname );
                if ( ! *name )
                    strcpy( name, "<no name>" );
                fl_add_browser_line( fd_control->groupbrowser, name );
                if ( is_selected( obj ) )
                    fl_select_browser_line( fd_control->groupbrowser, i );
            }
            else if ( obj->objclass == FL_END_GROUP )
                i++;
    }

    fl_unfreeze_form( fd_control->groupbrowser->form );
}


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