Albrecht Schlosser wrote:
> Alvin wrote:
>
>> I'd really appreciated it if someone could take a look at the test
>> program attached and see what I am doing wrong?
>
> I didn't really look deeply at your program, but here's my wild guess:
>
> (1) picked() is not called, because Fl_Menu_::picked() is not virtual.
> (2) you should use a callback instead
>
> From Fl_Menu_.cxx:
>
> // When user picks a menu item, call this. It will do the callback.
>
> HTH
> Albrecht
Thanks. I think picked() not being virtual may be the problem. I have
managed to come up with a slightly better workaround but I still don't like
it since it still uses handle().
Basically, I filtered for which events the tooltipification logic occurs
under. I do not like this workaround since it relies on this version of
Fl_Choice.cxx::handle() in order to know what events matter. These could
change or more added or have bug fixes applied.
The intuitive way would be to override the picked() method since it is
called by Fl_Choice when an entry has been selected. Therefore, the derived
which can act regardless of how the item was selected (FL_PUSH, Shortcut,
etc.)
Attaching a callback would add too much complexity as the Fl_Smart_Choice
would have to manage a callback from the user and well as provide
its "derived behaviour" callback to Fl_Choice.
Here's the Fl_Smart_Choice::handle() function that simply drops into the
tarball I attached to the original post.
int Fl_Smart_Choice::handle(int e)
{
switch(e)
{
case FL_KEYBOARD:
case FL_PUSH:
case FL_SHORTCUT:
if(Fl_Choice::handle(e) && text())
{
fl_font(textfont(), textsize());
int tw = 0;
int th = 0;
fl_measure(text(), tw, th, 1);
int ww = w() - Fl::box_dw(box()) - (h() > 20 ? 20 : h());
if(tw > ww) // item's text is longer than we are wide
tooltip(text());
else // item's text fits nicely in our width
tooltip(0);
printf("text=%s tw=%d ww=%d tooltip=%s\n",
text(), tw, ww, tooltip());
return 1;
}
break;
default:
;
}
return Fl_Choice::handle(e);
}
--
Alvin
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk