diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2012-07-31 20:40:14 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2012-07-31 20:40:14 +0100 |
commit | 941a48dabd93323f11ac2b18803289d30e8b3a78 (patch) | |
tree | 0fca5e05f1cabdc457f633853d4c31263581df14 /framebuffer | |
parent | 4125a8afdfcbc18fb5e0e60b49d6d5cdd44d008c (diff) | |
download | netsurf-941a48dabd93323f11ac2b18803289d30e8b3a78.tar.gz netsurf-941a48dabd93323f11ac2b18803289d30e8b3a78.tar.bz2 |
When setting fbtk caret, register callback for redrawing caret removal.
Diffstat (limited to 'framebuffer')
-rw-r--r-- | framebuffer/fbtk.h | 3 | ||||
-rw-r--r-- | framebuffer/fbtk/fbtk.c | 11 | ||||
-rw-r--r-- | framebuffer/fbtk/widget.h | 8 | ||||
-rw-r--r-- | framebuffer/gui.c | 34 |
4 files changed, 31 insertions, 25 deletions
diff --git a/framebuffer/fbtk.h b/framebuffer/fbtk.h index 131ae6521..a3f01557a 100644 --- a/framebuffer/fbtk.h +++ b/framebuffer/fbtk.h @@ -273,7 +273,8 @@ bool fbtk_set_pos_and_size(fbtk_widget_t *widget, int x, int y, int width, int h * @param y y-coordinate of caret top * @param height height of caret */ -void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height); +void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height, + void (*remove_caret)(fbtk_widget_t *widget)); /** Map a widget and request it is redrawn. */ diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c index 8e8bc112c..d333d20ff 100644 --- a/framebuffer/fbtk/fbtk.c +++ b/framebuffer/fbtk/fbtk.c @@ -224,21 +224,30 @@ fbtk_set_pos_and_size(fbtk_widget_t *widget, /* exported function docuemnted in fbtk.h */ void fbtk_set_caret(fbtk_widget_t *widget, bool set, - int x, int y, int height) + int x, int y, int height, + void (*remove_caret)(fbtk_widget_t *widget)) { fbtk_widget_t *root; assert(widget != NULL); root = fbtk_get_root_widget(widget); + if (root->u.root.caret.owner != NULL && + root->u.root.caret.remove_cb != NULL) + root->u.root.caret.remove_cb(widget); + if (set) { + assert(remove_caret != NULL); + root->u.root.caret.owner = widget; root->u.root.caret.x = x; root->u.root.caret.y = y; root->u.root.caret.height = height; + root->u.root.caret.remove_cb = remove_caret; } else { root->u.root.caret.owner = NULL; + root->u.root.caret.remove_cb = NULL; } } diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h index 3521cc358..5622723ee 100644 --- a/framebuffer/fbtk/widget.h +++ b/framebuffer/fbtk/widget.h @@ -168,6 +168,7 @@ struct fbtk_widget_s { int x; /* relative to owner */ int y; /* relative to owner */ int height; + void (*remove_cb)(fbtk_widget_t *widget); } caret; } root; @@ -182,9 +183,10 @@ struct fbtk_widget_s { bool outline; fbtk_enter_t enter; void *pw; - int idx; - int len; - int width; + int idx; /* caret pos in text */ + int len; /* text length */ + int width; /* text width in px */ + int idx_offset; /* caret pos in pixels */ } text; /* application driven widget */ diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 216791d2b..cae17c52d 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -1499,24 +1499,31 @@ gui_window_stop_throbber(struct gui_window *gw) } -void -gui_window_place_caret(struct gui_window *g, int x, int y, int height) +static void +gui_window_remove_caret_cb(fbtk_widget_t *widget) { - struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser); + struct browser_widget_s *bwidget = fbtk_get_userpw(widget); int c_x, c_y, c_h; - if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) { + if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) { /* browser window already had caret: * redraw its area to remove it first */ - fb_queue_redraw(g->browser, + fb_queue_redraw(widget, c_x - bwidget->scrollx, c_y - bwidget->scrolly, c_x + 1 - bwidget->scrollx, c_y + c_h - bwidget->scrolly); } +} + +void +gui_window_place_caret(struct gui_window *g, int x, int y, int height) +{ + struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser); /* set new pos */ - fbtk_set_caret(g->browser, true, x, y, height); + fbtk_set_caret(g->browser, true, x, y, height, + gui_window_remove_caret_cb); /* redraw new caret pos */ fb_queue_redraw(g->browser, @@ -1529,21 +1536,8 @@ gui_window_place_caret(struct gui_window *g, int x, int y, int height) void gui_window_remove_caret(struct gui_window *g) { - struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser); - int c_x, c_y, c_h; - - if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) { - /* browser window already had caret: - * redraw its area to remove it first */ - fb_queue_redraw(g->browser, - c_x - bwidget->scrollx, - c_y - bwidget->scrolly, - c_x + 1 - bwidget->scrollx, - c_y + c_h - bwidget->scrolly); - } - /* remove caret */ - fbtk_set_caret(g->browser, false, 0, 0, 0); + fbtk_set_caret(g->browser, false, 0, 0, 0, NULL); } void |