When setting fbtk caret, register callback for redrawing caret removal.

This commit is contained in:
Michael Drake 2012-07-31 20:40:14 +01:00
parent 4125a8afdf
commit 941a48dabd
4 changed files with 31 additions and 25 deletions

View File

@ -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.
*/

View File

@ -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;
}
}

View File

@ -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 */

View File

@ -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