From 282927c4582d34b9608d04df20d5059e6a63cfe4 Mon Sep 17 00:00:00 2001 From: toni Date: Thu, 7 May 2015 12:36:31 +0200 Subject: status window code stub --- ui_nwindow.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ui_nwindow.c (limited to 'ui_nwindow.c') diff --git a/ui_nwindow.c b/ui_nwindow.c new file mode 100644 index 0000000..7098097 --- /dev/null +++ b/ui_nwindow.c @@ -0,0 +1,70 @@ +#include +#include + +#include "ui.h" +#include "ui_nwindow.h" + + +struct txtwindow * +init_txtwindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height, chtype attrs, window_func cb_update) +{ + struct txtwindow *a = calloc(1, sizeof(struct txtwindow)); + + a->x = x; + a->y = y; + a->width = width; + a->height = height; + a->scrollable = false; + a->title_len = INITIAL_TITLE_LEN; + a->text_len = INITIAL_TEXT_LEN; + a->title = calloc(a->title_len, sizeof(char)); + a->text = calloc(a->text_len, sizeof(char)); + a->attrs = attrs; + a->window_func = cb_update; + return (a); +} + +void +free_txtwindow(struct txtwindow *a) +{ + if (a->text) { + free(a->text); + } + if (a->title) { + free(a->title); + } + free(a); +} + +int +txtwindow_cb(WINDOW *win, void *data, bool timedout) +{ + struct txtwindow *a = (struct txtwindow *) data; + return (UICB_OK); +} + +void inline +register_txtwindow(struct txtwindow *a) +{ + register_ui_elt(txtwindow_cb, (void *) a, NULL); +} + +static inline size_t +__do_textcpy(char **p_dest, size_t sz_dest, const char *p_src, size_t sz_src) +{ + if (sz_src > sz_dest) { + *p_dest = (char *) realloc(*p_dest, sz_dest * sizeof(char)); + } + memset(*p_dest, '\0', sz_dest); + return sz_dest; +} + +void +set_txtwindow_text(struct txtwindow *a, const char *text) +{ + size_t len = strlen(text); + + if (len > a->text_len) { + a->text_len = __do_textcpy(&a->text, a->text_len, text, len); + } +} -- cgit v1.2.3