Alvin wrote:
> Hello all,
>
> I am deriving a widget from Fl_Scroll. The problem I am having is
> detecting when the user has used Fl_Scroll's scrollbars.
Well, I found a solution. Not sure if I like it much, but I think this is
the only way to do it without reinventing the scrolling widget altogether.
My solution is to hooking my own scrollbar callback into
Fl_Scroll::hscrollbar and Fl_Scroll::scrollbar. Before doing so, I save the
pointer to their original callback (set by Fl_Scroll's ctor). Then in my
callback, I call the scrollbar's original callback then do my stuff.
For example, here's something that is representative of what I have to for
my widget to see Fl_Scroll scrolling:
In my widget's ctor I do:
// store callback that was set by Fl_Scroll
hcb = hscrollbar.callback();
vcb = scrollbar.callback();
// Hook in our own callback
hscrollbar.callback(hscrollbar_hook);
scrollbar.callback(vscrollbar_hook);
Definition of hscrollbar_hook is:
void Fl_Canvas::hscrollbar_hook(Fl_Widget *o, void *)
{
Fl_Canvas *canvas = (Fl_Canvas*)(o->parent());
canvas->xpos = canvas->xposition(); // store position before
scrolling
canvas->hcb(o, 0); // call the original callback
// Apply the change in scrolling - basically I need to use
// how much the viewport (Fl_Scroll) was scrolled by
canvas->sx += (canvas->xpos - canvas->xposition());
}
Basically, the last line is what I needed to do. However, to determine how
much the scroll was changed, I need to know the before and after values.
>From what I can tell by reading Fl_Scroll.cxx, Fl_Scroll does not call its
callback (ever??).
Anyone have any other ideas that would be cleaner that this?
--
Alvin
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk