[go: up one dir, main page]

File: child.c

package info (click to toggle)
libforms1 1.0-8
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,648 kB
  • ctags: 14,351
  • sloc: ansic: 90,441; makefile: 9,902; sh: 8
file content (276 lines) | stat: -rw-r--r-- 5,286 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
 *
 *  This file is part of the XForms library package.
 *
 * 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: child.c,v 1.0 2002/05/08 05:16:30 zhao Release $
 *.
 *  This file is part of the XForms library package.
 *  Copyright (c) 1996-2002  T.C. Zhao 
 *  All rights reserved.
 *.
 *
 * Temprary hack to get composite (sort of) object support in
 *
 */
#include "forms.h"

void
fl_add_child(FL_OBJECT * parent, FL_OBJECT * child)
{
    FL_OBJECT *t;

    if (child->form)
	fl_delete_object(child);

    if (child->child || !child->parent)
	child->parent = parent;

    parent->parent = parent;
    child->is_child = 1;

    /* copy gravity attributes */
    child->nwgravity = parent->nwgravity;
    child->segravity = parent->segravity;
    child->resize = parent->resize;

    if (parent->child == 0)
	parent->child = child;
    else
    {
	for (t = parent->child; t && t->nc; t = t->nc)
	    ;
	t->nc = child;
    }

    child->nc = child->child;

}

void
fl_delete_child(FL_OBJECT * child)
{
    FL_OBJECT *obj;

    for (obj = child->parent->child; obj && obj->nc != child; obj = obj->nc)
	;
    if (obj)
    {
	obj->nc = child->nc;
	child->is_child = 0;
	child->nc = 0;
    }
}

void
fl_hide_composite(FL_OBJECT * ob)
{
    FL_OBJECT *tmp = ob->child;

    for (; tmp; tmp = tmp->nc)
    {
	if (tmp->objclass == FL_CANVAS)
	    fl_hide_canvas(tmp);
	tmp->visible = 0;
    }
}


void
fl_delete_composite(FL_OBJECT * ob)
{
    FL_OBJECT *tmp = ob->child;

    for (; tmp; tmp = tmp->nc)
    {
	if (tmp->form)
	    fl_delete_object(tmp);
    }
}

void
fl_show_composite(FL_OBJECT * ob)
{
    FL_OBJECT *tmp = ob->child;

    for (; tmp; tmp = tmp->nc)
	tmp->visible = 1;
}

void
fl_deactivate_composite(FL_OBJECT * ob)
{
    FL_OBJECT *tmp = ob->child;

    ob->parent->active = DEACTIVATED;
    for (; tmp; tmp = tmp->nc)
	tmp->active = DEACTIVATED;;
}

void
fl_activate_composite(FL_OBJECT * ob)
{
    FL_OBJECT *tmp = ob->child;

    ob->parent->active = 1;
    for (; tmp; tmp = tmp->nc)
	tmp->active = 1;
}

void
fl_set_composite_resize(FL_OBJECT * ob, unsigned resize)
{
    FL_OBJECT *tmp = ob->child;

    for (; tmp; tmp = tmp->nc)
	tmp->resize = resize;
}

void
fl_set_composite_gravity(FL_OBJECT * ob, unsigned nw, unsigned se)
{
    FL_OBJECT *tmp = ob->child;

    for (; tmp; tmp = tmp->nc)
    {
	tmp->nwgravity = nw;
	tmp->segravity = se;
    }
}

void
fl_insert_composite_after(FL_OBJECT * comp, FL_OBJECT * node)
{
    FL_OBJECT *next, *tmp, *prev;
    FL_FORM *form;

    if (!comp || !node)
    {
	M_err("InsertComp", "Bad argument");
	return;
    }

    if (!(form = node->form))
    {
	M_err("InsertComp", "null form");
	return;
    }

    comp->form = form;

    next = node->next;
    node->next = comp;
    comp->prev = node;
    comp->child->form = form;
    comp->next = comp->child;
    comp->next->prev = comp;

    prev = comp;

    for (tmp = comp->child; tmp && tmp->nc; prev = tmp, tmp = tmp->nc)
    {
	tmp->form = form;
	tmp->next = tmp->nc;
	tmp->prev = prev;
    }

    tmp->next = next;
    tmp->prev = prev;
    tmp->form = form;

    if (form->last == node)
	form->last = tmp;

}

/* change the parent of a composite. Need to take care for
 * composite of composite
 */
void
fl_change_composite_parent(FL_OBJECT * comp, FL_OBJECT * newparent)
{
    FL_OBJECT *tmp = comp->child;

    comp->parent = newparent;
    for (; tmp; tmp = tmp->nc)
	if (tmp->parent == comp)
	    tmp->parent = newparent;
}


void
fl_add_composite(FL_FORM * form, FL_OBJECT * ob)
{
    FL_OBJECT *tmp = ob->child, *tmp1 = ob;

    for (; tmp; tmp1 = tmp, tmp = tmp->nc)
	fl_add_object(form, tmp);

    if (form->last == ob)
	form->last = tmp1;
}


FL_OBJECT *
fl_get_object_component(FL_OBJECT * composite, int objclass, int type, int numb)
{
    FL_OBJECT *tmp;
    int n;

    for (n = 0, tmp = composite->child; tmp; tmp = tmp->nc)
    {
	if (tmp->objclass == objclass && (tmp->type == type || type < 0))
	{
	    if ((++n) >= numb)
		return tmp;
	}
    }

    M_err("GetComponent", "requested object not found");

    return 0;
}

void
fl_mark_composite_for_redraw(FL_OBJECT * ob)
{
    FL_OBJECT *tmp = ob->child;
    for (; tmp; tmp = tmp->nc)
    {
       /* M_err("Marking", "%s", fl_object_class_name(ob)); */
	tmp->redraw = 1;
    }
}

/*
 * copy the parent attributes. gravity stuff is taken care of by
 * fl_add_child()
 */

void
fl_inherit_attributes(FL_OBJECT * parent, FL_OBJECT * child)
{
    child->bw = parent->bw;
    child->lcol = parent->lcol;
    child->col1 = parent->col1;
    child->lsize = parent->lsize;
    child->lstyle = parent->lstyle;
}