13 static int getc_cb(TXObj
*obj
) {
14 return wgetch(obj
->win
);
17 void tx_obj_size_cb_set(TXObj
*obj
, size_fn size_cb
) {
18 obj
->size_cb
= size_cb
;
21 void tx_obj_idle_cb_set(TXObj
*obj
, obj_fn idle_cb
) {
22 obj
->idle_cb
= idle_cb
;
25 void tx_obj_getc_cb_set(TXObj
*obj
, getc_fn getc_cb
) {
26 obj
->getc_cb
= getc_cb
;
29 void tx_obj_rsze_cb_set(TXObj
*obj
, obj_fn rsze_cb
) {
30 obj
->rsze_cb
= rsze_cb
;
33 /* apply cb to a box then each object in the box else apply cb to itself */
34 void tx_obj_map(TXObj
*obj
, obj_fn cb
) {
36 if (obj
->type
== TX_BOX
) {
39 list_for_each_entry(entry
, &box
->node
, node
) {
40 tx_obj_map(entry
, cb
);
47 /* setup background window for border and static text, ie titles */
48 void tx_obj_setup(TXObj
*obj
) {
50 wresize(obj
->bwin
, obj
->h
, obj
->w
);
51 mvwin(obj
->bwin
, obj
->y
, obj
->x
);
54 obj
->bwin
= newwin(obj
->h
, obj
->w
, obj
->y
, obj
->x
);
55 obj
->bpanel
= new_panel(obj
->bwin
);
58 void tx_obj_size_set(TXObj
*obj
, int x
, int y
, int w
, int h
) {
59 obj
->x
= x
; obj
->y
= y
;
60 obj
->w
= w
; obj
->h
= h
;
63 void tx_obj_border(TXObj
*obj
) {
65 tx_obj_size_set(obj
, obj
->x
+1, obj
->y
+1, obj
->w
-2, obj
->h
-2);
69 void tx_obj_idle(TXObj
*obj
) {
70 if (obj
->idle_cb
) obj
->idle_cb(obj
);
73 void tx_obj_draw(TXObj
*obj
) {
79 void tx_obj_resize(TXObj
*obj
) {
80 if (obj
->flags
& TX_OBJ_ROOT
) {
81 tx_obj_size_set(obj
, 0, 0, COLS
, LINES
);
82 /* this allows the object to set the size if root is not in a box*/
83 if (obj
->type
!= TX_BOX
) obj
->size_cb(obj
, obj
->h
, obj
->w
);
86 /* setup back window */
88 /* draw border on back window */
89 if (obj
->flags
& TX_OBJ_BORDER
) tx_obj_border(obj
);
91 /* let object routines do whatever needs to be done */
93 /* setup win object and draw on background, ie titles */
94 if (obj
->init_cb
) obj
->init_cb(obj
);
96 /* user defined routines, ie setup columns */
97 if (obj
->rsze_cb
) obj
->rsze_cb(obj
);
100 void tx_obj_reset(TXObj
*obj
) {
101 /* lets start fresh */
102 getmaxyx(obj
->bwin
, obj
->h
, obj
->w
);
103 getbegyx(obj
->bwin
, obj
->y
, obj
->x
);
107 /* object flag manipluation */
108 void tx_obj_flag_set(TXObj
*obj
, int flag
, int set
) {
116 int tx_obj_flag_get(TXObj
*obj
, int flag
) {
117 return obj
->flags
& flag
;
120 int tx_obj_flag_toggle(TXObj
*obj
, int flag
) {
121 int set
= (obj
->flags
& flag
) ? 0 : 1;
122 tx_obj_flag_set(obj
, flag
, set
);
126 void tx_obj_operate(TXObj
*obj
) {
131 switch(key
= obj
->getc_cb(obj
)) {
133 case EMERGENCY
: tx_free(); return;
134 case ERR
: tx_obj_map(tx_obj_root
, tx_obj_idle
); break;
135 case KEY_RESIZE
: tx_obj_map(tx_obj_root
, tx_obj_resize
); break;
136 default: if (obj
->oper_cb
) obj
->oper_cb(obj
, key
); break;
141 int tx_obj_init(TXObj
*obj
, int type
, int flags
) {
142 memset(obj
, 0, sizeof(TXObj
));
147 obj
->getc_cb
= getc_cb
;
150 case TX_LIST
: tx_list_new(obj
); break;
151 case TX_BOX
: tx_box_init(obj
); break;
152 default: return 0; break;
155 /* make inital object fill the screen */
156 if (flags
& TX_OBJ_ROOT
)
159 if (flags
& TX_OBJ_FOCUS
)