From 5124b8a02a2adb72a7352f14e06dc2a773afbc1f Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 12 Jan 2013 20:46:01 +0000 Subject: [PATCH] Add textarea_setup struct to textarea_create API. --- desktop/textarea.c | 43 +++++++++++++++++++++++++++++++++---------- desktop/textarea.h | 23 +++++++++++++++++++++-- desktop/tree.c | 20 ++++++++++++++++++-- 3 files changed, 72 insertions(+), 14 deletions(-) diff --git a/desktop/textarea.c b/desktop/textarea.c index 16c2f4616..3ab8c5af5 100644 --- a/desktop/textarea.c +++ b/desktop/textarea.c @@ -75,6 +75,17 @@ struct textarea { int vis_width; /**< Visible width, in pixels */ int vis_height; /**< Visible height, in pixels */ + int pad_top; + int pad_right; + int pad_bottom; + int pad_left; + + int border_width; + colour border_col; + + plot_font_style_t fstyle; /**< Text style */ + plot_font_style_t sel_fstyle; /**< Text style */ + char *text; /**< UTF-8 text */ unsigned int text_alloc; /**< Size of allocated text */ unsigned int text_len; /**< Length of text, in bytes */ @@ -92,8 +103,6 @@ struct textarea { int sel_start; /**< Character index of sel start(inclusive) */ int sel_end; /**< Character index of sel end(exclusive) */ - plot_font_style_t fstyle; /**< Text style */ - int line_count; /**< Count of lines */ #define LINE_CHUNK_SIZE 16 struct line_info *lines; /**< Line info array */ @@ -608,8 +617,7 @@ static bool textarea_replace_text(struct textarea *ta, unsigned int start, /* exported interface, documented in textarea.h */ -struct textarea *textarea_create(int width, int height, - textarea_flags flags, const plot_font_style_t *style, +struct textarea *textarea_create(const textarea_setup *setup, textarea_redraw_request_callback redraw_request, void *data) { struct textarea *ret; @@ -627,14 +635,30 @@ struct textarea *textarea_create(int width, int height, ret->redraw_request = redraw_request; ret->data = data; - ret->vis_width = width; - ret->vis_height = height; + + ret->flags = setup->flags; + ret->vis_width = setup->width; + ret->vis_height = setup->height; + + ret->pad_top = setup->pad_top; + ret->pad_right = setup->pad_right; + ret->pad_bottom = setup->pad_bottom; + ret->pad_left = setup->pad_left; + + ret->border_width = setup->border_width; + ret->border_col = setup->border_col; + + ret->fstyle = setup->text; + + ret->sel_fstyle = setup->text; + ret->sel_fstyle.foreground = setup->selected_text; + ret->sel_fstyle.background = setup->selected_bg; + ret->scroll_x = 0; ret->scroll_y = 0; ret->drag_start_char = 0; - ret->flags = flags; ret->text = malloc(64); if (ret->text == NULL) { LOG(("malloc failed")); @@ -646,11 +670,10 @@ struct textarea *textarea_create(int width, int height, ret->text_len = 1; ret->text_utf8_len = 0; - ret->fstyle = *style; - ret->line_height = FIXTOINT(FDIV((FMUL(FLTTOFIX(1.2), FMUL(nscss_screen_dpi, - INTTOFIX((style->size / FONT_SIZE_SCALE))))), F_72)); + INTTOFIX((setup->text.size / + FONT_SIZE_SCALE))))), F_72)); ret->caret_pos.line = ret->caret_pos.char_off = 0; ret->caret_x = MARGIN_LEFT; diff --git a/desktop/textarea.h b/desktop/textarea.h index e4fa2c7aa..a798e7c9f 100644 --- a/desktop/textarea.h +++ b/desktop/textarea.h @@ -36,6 +36,26 @@ typedef enum textarea_flags { TEXTAREA_READONLY = (1 << 2) } textarea_flags; +typedef struct textarea_setup { + textarea_flags flags; + + int width; + int height; + + int pad_top; + int pad_right; + int pad_bottom; + int pad_left; + + int border_width; + colour border_col; + + colour selected_text; + colour selected_bg; + plot_font_style_t text; + +} textarea_setup; + struct textarea; @@ -54,8 +74,7 @@ typedef void(*textarea_redraw_request_callback)(void *data, int x, int y, * \param data user specified data which will be passed to redraw callbacks * \return Opaque handle for textarea or 0 on error */ -struct textarea *textarea_create(int width, int height, - textarea_flags flags, const plot_font_style_t *style, +struct textarea *textarea_create(const textarea_setup *setup, textarea_redraw_request_callback redraw_request, void *data); /** diff --git a/desktop/tree.c b/desktop/tree.c index 250bdd861..df2e9263f 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -2935,6 +2935,7 @@ void tree_start_edit(struct tree *tree, struct node_element *element) { struct node *parent; int width, height; + textarea_setup ta_setup; assert(tree != NULL); assert(element != NULL); @@ -2959,8 +2960,23 @@ void tree_start_edit(struct tree *tree, struct node_element *element) if (element->type == NODE_ELEMENT_TEXT_PLUS_ICON) width -= NODE_INSTEP; - tree->textarea = textarea_create(width, height, TEXTAREA_DEFAULT, - &plot_fstyle, tree_textarea_redraw_request, tree); + ta_setup.flags = TEXTAREA_DEFAULT; + ta_setup.width = width; + ta_setup.height = height; + ta_setup.pad_top = 0; + ta_setup.pad_right = 4; + ta_setup.pad_bottom = 0; + ta_setup.pad_left = 4; + ta_setup.border_width = 1; + ta_setup.border_col = 0x000000; + ta_setup.selected_text = 0xffffff; + ta_setup.selected_bg = 0x000000; + ta_setup.text = plot_fstyle; + ta_setup.text.foreground = 0x000000; + ta_setup.text.background = 0xffffff; + + tree->textarea = textarea_create(&ta_setup, + tree_textarea_redraw_request, tree); if (tree->textarea == NULL) { tree_stop_edit(tree, false); return;