http://mulliner.org/bluetooth/xkbdbthid-0.1_src.tar.gz
[xkbdbthid.git] / xkbd-0.8.15_bthid / src / box.c
1 /* 
2    xkbd - xlib based onscreen keyboard.
3
4    Copyright (C) 2001 Matthew Allum
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 #include "structs.h"
21
22 #define WIDGET_BOX    0
23 #define WIDGET_BUTTON 1
24
25 box* box_new(void)
26 {
27   box *bx = NULL;
28   bx = malloc(sizeof(box));
29   bx->root_kid = NULL;
30   bx->tail_kid = NULL;
31   bx->act_width = 0;
32   bx->act_height = 0;
33   bx->parent = NULL;
34   return bx;
35 }
36
37 button *box_add_button(box *bx, button *but)
38 {
39   list *new_ptr  = NULL;
40
41   but->parent = bx; /* set its parent */
42
43   if (bx->root_kid == NULL) /* new list */
44     {
45       bx->root_kid = (list *)malloc(sizeof(list));
46       bx->root_kid->next = NULL;
47       bx->tail_kid = bx->root_kid;
48       bx->root_kid->data = but;
49       bx->root_kid->type = WIDGET_BUTTON;
50       
51       return but;
52     } 
53
54   new_ptr = bx->tail_kid;
55   new_ptr->next = malloc(sizeof(list));
56   new_ptr->next->next = NULL;
57   new_ptr->next->data = but;
58   new_ptr->next->type = WIDGET_BUTTON;
59   bx->tail_kid = new_ptr->next;
60   
61   return but;
62
63 }
64
65 box *box_add_box(box *bx, box *b)
66 {
67   list *new_ptr  = NULL;
68
69   b->parent = bx; /* set its parent */
70
71   if (bx->root_kid == NULL) /* new list */
72     {
73       bx->root_kid = (list *)malloc(sizeof(list));
74       bx->root_kid->next = NULL;
75       bx->tail_kid = bx->root_kid;
76       bx->root_kid->data = b;
77       bx->root_kid->type = WIDGET_BOX;
78       return b;
79     } 
80
81   new_ptr = bx->tail_kid;
82   new_ptr->next = malloc(sizeof(list));
83   new_ptr->next->next = NULL;
84   new_ptr->next->data = b;
85   new_ptr->next->type = WIDGET_BOX;
86   bx->tail_kid = new_ptr->next;
87   return b;
88
89 }
90
91 void box_list_contents(box *bx)
92 {
93   list *ptr = bx->root_kid;
94   if (ptr == NULL) return;
95   while (ptr != NULL)
96     {
97       /*      if (ptr->type == WIDGET_BUTTON)
98               printf("listing %s\n", ((button *)ptr->data)->txt); */
99       printf("size is %i\n", sizeof(*(ptr->data)));
100       ptr = ptr->next;
101     }
102 }
103
104
105