aboutsummaryrefslogtreecommitdiffstats
path: root/src/gwin/gcontainer.c
blob: 9828118370b911ca261019000be3beb5512b14b0 (plain)
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
/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.org/license.html
 */

#include "gfx.h"

#if GFX_USE_GWIN && GWIN_NEED_CONTAINERS

#include "src/gwin/class_gwin.h"

void _gcontainerInit(void)
{
}

void _gcontainerDeinit(void)
{
}

GHandle _gcontainerCreate(GDisplay *g, GContainerObject *pgc, const GWidgetInit *pInit, const gcontainerVMT *vmt) {
	if (!(pgc = (GContainerObject *)_gwidgetCreate(g, (GWidgetObject *)pgc, pInit, &vmt->gw)))
		return 0;

	pgc->g.flags |= GWIN_FLG_CONTAINER;

	return 	&pgc->g;
}

void _gcontainerDestroy(GHandle gh) {
	GHandle		child;

	while((child = gwinGetFirstChild(gh)))
		gwinDestroy(child);
	_gwidgetDestroy(gh);
}

void _gwinRecurse(GHandle gh, bool_t (*fn)(GHandle gh)) {
	if (fn(gh) && (gh->flags & GWIN_FLG_CONTAINER)) {
		// Apply to this windows children
		for(gh = gwinGetFirstChild(gh); gh; gh = gwinGetSibling(gh)) {
			// Only recurse when we have to. Otherwise apply it directly
			if ((gh->flags & GWIN_FLG_CONTAINER))
				_gwinRecurse(gh, fn);
			else
				fn(gh);
		}
	}
}

GHandle gwinGetFirstChild(GHandle gh) {
	GHandle		child;

	for(child = gwinGetNextWindow(0); child; child = gwinGetNextWindow(child))
		if (child->parent == gh)
			return child;
	return 0;
}

GHandle gwinGetSibling(GHandle gh) {
	GHandle		child;

	for(child = gwinGetNextWindow(gh), gh = gh->parent; child; child = gwinGetNextWindow(child))
		if (child->parent == gh)
			return child;
	return 0;
}

#endif /* GFX_USE_GWIN && GWIN_NEED_CONTAINERS */
/** @} */