aboutsummaryrefslogtreecommitdiff
path: root/ui_nwindow.c
diff options
context:
space:
mode:
authortoni <toni@devlap.local>2015-05-07 12:36:31 +0200
committertoni <toni@devlap.local>2015-05-07 12:36:31 +0200
commit282927c4582d34b9608d04df20d5059e6a63cfe4 (patch)
treea7e9d395f272afa3170d59bec80d123b6f23f900 /ui_nwindow.c
parent590d34f183c9abc60068a767426edbfec30cda3e (diff)
status window code stub
Diffstat (limited to 'ui_nwindow.c')
-rw-r--r--ui_nwindow.c70
1 files changed, 70 insertions, 0 deletions
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 <stdlib.h>
+#include <string.h>
+
+#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);
+ }
+}