File: fd_groups.c

package info (click to toggle)
libforms1 1.0-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,648 kB
  • ctags: 14,351
  • sloc: ansic: 90,441; makefile: 9,902; sh: 8
file content (158 lines) | stat: -rw-r--r-- 3,844 bytes parent folder | download | duplicates (3)
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
/*
 *
 * 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.
 *
 */


/*
 * $Id: fd_groups.c,v 1.0 2002/05/08 05:27:39 zhao Release $
 *
 *.
 *  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.
 *
 */

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

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

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

static FL_OBJECT *begobj[MAXGROUP];	/* Begin objects of the groups */

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

/* Sets the current group in the form */
void
group_cb(FL_OBJECT * obj, long 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, long arg)
{
    char name[MAX_VAR_LEN], cbname[MAX_VAR_LEN], argname[MAX_VAR_LEN];
    int i, numb = 0;
    const char *s;

    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 was selected");
	return;
    }

    get_object_name(begobj[numb], name, cbname, argname);
    if (!(s = fl_show_input("Give the new group name", name)))
	return;

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

/************ MAIN ROUTINES ******************/

/* 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 = 1;

    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 */
    obj = cur_form->first;
    while (obj != NULL)
    {
	if (obj->objclass == FL_BEGIN_GROUP)
	{
	    begobj[i] = obj;
	    get_object_name(obj, name, cbname, argname);
	    if (name[0] == '\0')
		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++;
	obj = obj->next;
    }
    fl_unfreeze_form(fd_control->groupbrowser->form);
}