/* exported function documented in fbtk.h */ void fbtk_click(fbtk_widget_t *widget, nsfb_event_t *event) { fbtk_widget_t *root; fbtk_widget_t *clicked; nsfb_bbox_t cloc; int x, y; /* ensure we have the root widget */ root = fbtk_get_root_widget(widget); nsfb_cursor_loc_get(root->u.root.fb, &cloc); clicked = fbtk_get_widget_at(root, cloc.x0, cloc.y0); if (clicked == NULL) return; if (fbtk_get_handler(clicked, FBTK_CBT_INPUT) != NULL) { fbtk_set_focus(clicked); } x = fbtk_get_absx(clicked); y = fbtk_get_absy(clicked); LOG("clicked %p at %d,%d", clicked, x, y); /* post the click */ fbtk_post_callback(clicked, FBTK_CBT_CLICK, event, cloc.x0 - x, cloc.y0 - y); }
/* exported function documented in fbtk.h */ int fbtk_destroy_widget(fbtk_widget_t *widget) { fbtk_widget_t *parent; int ret = 0; ret = fbtk_post_callback(widget, FBTK_CBT_DESTROY); while (widget->first_child != NULL) { fbtk_destroy_widget(widget->first_child); } parent = widget->parent; if (parent != NULL) { /* unlink from siblings */ if (widget->prev != NULL) { widget->prev->next = widget->next; } else { /* must be the first widget, unlink from parent */ parent->first_child = widget->next; } if (widget->next != NULL) { widget->next->prev = widget->prev; } else { /* must be the last widget, unlink from parent */ parent->last_child = widget->prev; } free(widget); } return ret; }
static int hscrollarea_click(fbtk_widget_t *widget, fbtk_callback_info *cbi) { int hscroll; int hpos; int newpos; int ret = 0; if (cbi->event->type != NSFB_EVENT_KEY_DOWN) { /* end all drags, just in case */ if (fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, NULL, NULL) != NULL) fbtk_tgrab_pointer(widget); return 0; } if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) { hscroll = ((widget->width - 4) * widget->u.scroll.thumb) / (widget->u.scroll.maximum - widget->u.scroll.minimum) ; hpos = ((widget->width - 4) * widget->u.scroll.position) / (widget->u.scroll.maximum - widget->u.scroll.minimum) ; } else { hscroll = (widget->width - 4); hpos = 0; } if (cbi->x < hpos) { /* left of bar */ newpos = widget->u.scroll.position - widget->u.scroll.page; if (newpos < widget->u.scroll.minimum) newpos = widget->u.scroll.minimum; ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, newpos); } else if (cbi->x > (hpos + hscroll)) { /* right of bar */ newpos = widget->u.scroll.position + widget->u.scroll.page; if (newpos > widget->u.scroll.maximum) newpos = widget->u.scroll.maximum; ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, newpos); } else { /* on bar - start drag */ widget->u.scroll.drag = cbi->x; widget->u.scroll.drag_position = hpos; fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, hscroll_drag, widget); fbtk_tgrab_pointer(widget); } return ret; }
static int do_redraw(nsfb_t *nsfb, fbtk_widget_t *widget) { nsfb_bbox_t plot_ctx; fbtk_widget_t *cwidget; /* child widget */ LOG(("DO REDRAW")); //__menuet__debug_out("\n***********\nDO REDRAW\n********\n"); /* check if the widget requires redrawing */ if (widget->redraw.needed == true) { plot_ctx.x0 = fbtk_get_absx(widget) + widget->redraw.x; plot_ctx.y0 = fbtk_get_absy(widget) + widget->redraw.y; plot_ctx.x1 = plot_ctx.x0 + widget->redraw.width; plot_ctx.y1 = plot_ctx.y0 + widget->redraw.height; LOG(("clipping %p %d,%d %d,%d", widget, plot_ctx.x0, plot_ctx.y0, plot_ctx.x1, plot_ctx.y1)); if (nsfb_plot_set_clip(nsfb, &plot_ctx) == true) { LOG(("POST CALLBACK")); //__menuet__debug_out("\n***********\nPOST CALLBACK\n********\n"); fbtk_post_callback(widget, FBTK_CBT_REDRAW); } widget->redraw.needed = false; } LOG(("DO CHILD")); //__menuet__debug_out("\n***********\nDO CHILD\n********\n"); /* walk the widgets children if child flag is set */ if (widget->redraw.child) { LOG(("DO CHILD 2")); //__menuet__debug_out("\n***********\nDO CHILD 2\n********\n"); cwidget = widget->last_child; while (cwidget != NULL) { LOG(("DO CHILD 3 ZZZ")); //__menuet__debug_out("\n***********\nDO CHILD 3 ZZZ\n********\n"); do_redraw(nsfb, cwidget); cwidget = cwidget->prev; } LOG(("DO CHILD 4")); //__menuet__debug_out("\n***********\nDO CHILD 4\n********\n"); widget->redraw.child = false; } LOG(("SUP")); //__menuet__debug_out("\n***********\nFIN REDRAW\n********\n"); return 1; }
/* exported function documented in fbtk.h */ void fbtk_input(fbtk_widget_t *root, nsfb_event_t *event) { fbtk_widget_t *input; root = fbtk_get_root_widget(root); /* obtain widget with input focus */ input = root->u.root.input; if (input == NULL) { LOG("No widget has input focus."); return; /* no widget with input */ } fbtk_post_callback(input, FBTK_CBT_INPUT, event); }
static int hscrollr_click(fbtk_widget_t *widget, fbtk_callback_info *cbi) { int newpos; fbtk_widget_t *scrollw = cbi->context; if (cbi->event->type != NSFB_EVENT_KEY_DOWN) return 0; newpos = scrollw->u.scroll.position + scrollw->u.scroll.page; if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb )) newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb); if (newpos == scrollw->u.scroll.position) return 0; return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLX, newpos); }
static int vscrollu_click(fbtk_widget_t *widget, fbtk_callback_info *cbi) { int newpos; fbtk_widget_t *scrollw = cbi->context; if (cbi->event->type != NSFB_EVENT_KEY_DOWN) return 0; newpos = scrollw->u.scroll.position - scrollw->u.scroll.page; if (newpos < scrollw->u.scroll.minimum) newpos = scrollw->u.scroll.minimum; if (newpos == scrollw->u.scroll.position) return 0; return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLY, newpos); }
static int hscrolll_click(fbtk_widget_t *widget, fbtk_callback_info *cbi) { int newpos; fbtk_widget_t *scrollw = cbi->context; if (cbi->event->type != NSFB_EVENT_KEY_DOWN) return 0; newpos = scrollw->u.scroll.position - scrollw->u.scroll.page; if (newpos < scrollw->u.scroll.minimum) newpos = scrollw->u.scroll.minimum; if (newpos == scrollw->u.scroll.position) { LOG(("horiz scroll was the same %d", newpos)); return 0; } return fbtk_post_callback(scrollw, FBTK_CBT_SCROLLX, newpos); }
static int vscroll_drag(fbtk_widget_t *widget, fbtk_callback_info *cbi) { int newpos; fbtk_widget_t *scrollw = cbi->context; newpos = ((widget->u.scroll.drag_position + (cbi->y - widget->u.scroll.drag)) * (widget->u.scroll.maximum - widget->u.scroll.minimum)) / (widget->height - 4); if (newpos < scrollw->u.scroll.minimum) newpos = scrollw->u.scroll.minimum; if (newpos > (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb )) newpos = (scrollw->u.scroll.maximum - scrollw->u.scroll.thumb); if (newpos == scrollw->u.scroll.position) return 0; return fbtk_post_callback(widget, FBTK_CBT_SCROLLY, newpos); }
/* exported function documented in fbtk.h */ void fbtk_warp_pointer(fbtk_widget_t *widget, int x, int y, bool relative) { fbtk_widget_t *root; fbtk_widget_t *moved; nsfb_bbox_t cloc; /* ensure we have the root widget */ root = fbtk_get_root_widget(widget); if (relative) { nsfb_cursor_loc_get(root->u.root.fb, &cloc); cloc.x0 += x; cloc.y0 += y; } else { cloc.x0 = x; cloc.y0 = y; } /* ensure cursor location lies within the root widget */ if (cloc.x0 < root->x) cloc.x0 = root->x; if (cloc.x0 >= (root->x + root->width)) cloc.x0 = (root->x + root->width) - 1; if (cloc.y0 < root->y) cloc.y0 = root->y; if (cloc.y0 >= (root->y + root->height)) cloc.y0 = (root->y + root->height) - 1; if (root->u.root.grabbed == NULL) { /* update the pointer cursor */ nsfb_cursor_loc_set(root->u.root.fb, &cloc); moved = fbtk_get_widget_at(root, cloc.x0, cloc.y0); x = fbtk_get_absx(moved); y = fbtk_get_absy(moved); /* post enter and leaving messages */ if (moved != root->u.root.prev) { fbtk_post_callback(root->u.root.prev, FBTK_CBT_POINTERLEAVE); root->u.root.prev = moved; fbtk_post_callback(root->u.root.prev, FBTK_CBT_POINTERENTER); } } else { /* pointer movement has been grabbed by a widget */ moved = root->u.root.grabbed; /* ensure pointer remains within widget boundary */ x = fbtk_get_absx(moved); y = fbtk_get_absy(moved); if (cloc.x0 < x) cloc.x0 = x; if (cloc.y0 < y) cloc.y0 = y; if (cloc.x0 > (x + moved->width)) cloc.x0 = (x + moved->width); if (cloc.y0 > (y + moved->height)) cloc.y0 = (y + moved->height); /* update the pointer cursor */ nsfb_cursor_loc_set(root->u.root.fb, &cloc); } /* post the movement */ fbtk_post_callback(moved, FBTK_CBT_POINTERMOVE, cloc.x0 - x, cloc.y0 - y); }
static int vscrollarea_click(fbtk_widget_t *widget, fbtk_callback_info *cbi) { int vscroll; int vpos; int newpos; int ret = 0; if (cbi->event->type != NSFB_EVENT_KEY_DOWN) { /* end all drags, just in case */ if (fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, NULL, NULL) != NULL) fbtk_tgrab_pointer(widget); return 0; } switch (cbi->event->value.keycode) { case NSFB_KEY_MOUSE_4: /* scroll up */ newpos = widget->u.scroll.position - widget->u.scroll.page; if (newpos < widget->u.scroll.minimum) newpos = widget->u.scroll.minimum; ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos); break; case NSFB_KEY_MOUSE_5: /* scroll down */ newpos = widget->u.scroll.position + widget->u.scroll.page; if (newpos > widget->u.scroll.maximum) newpos = widget->u.scroll.maximum; ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos); break; default: if ((widget->u.scroll.maximum - widget->u.scroll.minimum) > 0) { vscroll = ((widget->height - 4) * widget->u.scroll.thumb) / (widget->u.scroll.maximum - widget->u.scroll.minimum) ; vpos = ((widget->height - 4) * widget->u.scroll.position) / (widget->u.scroll.maximum - widget->u.scroll.minimum) ; } else { vscroll = (widget->height - 4); vpos = 0; } if (cbi->y < vpos) { /* above bar */ newpos = widget->u.scroll.position - widget->u.scroll.thumb; if (newpos < widget->u.scroll.minimum) newpos = widget->u.scroll.minimum; ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos); } else if (cbi->y > (vpos + vscroll)) { /* below bar */ newpos = widget->u.scroll.position + widget->u.scroll.thumb; if (newpos > widget->u.scroll.maximum) newpos = widget->u.scroll.maximum; ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, newpos); } else { /* on bar - start drag */ widget->u.scroll.drag = cbi->y; widget->u.scroll.drag_position = vpos; fbtk_set_handler(widget, FBTK_CBT_POINTERMOVE, vscroll_drag, widget); fbtk_tgrab_pointer(widget); } } return ret; }