Thanks for the fix. My solution for the moment is to override the handle
function. It would be easier to handle with when() but now I need to
detect some other user interactions too so there is no way around
overriding the handle function.

> On 02/20/12 04:09, Geoffrey Mellar wrote:
>> Hello,
>> i want a Fl_tree widget to call the callback function
>> only if there is a double click.
> 
>       Yes, there should really be an example that
>       shows how to do this. If there was, this bug
>       probably would have been caught.
> 
>> Because there is no
>> FL_WHEN_DOUBLE_CLICK or something else I decided to
>> use <tree>.when(FL_WHEN_NEVER). With this option enabled,
>> a callback should never happen. There is a handle function
>> to recognize the double click.
> 
>> This works fine but despite
>> the call to wid_waypoint_list.when(FL_WHEN_NEVER); there are
>> also callbacks on every other widget action. Is anyone
>> familiar with this problem?
> 
>       Sounds like a bug in Fl_Tree's handling of when().
>       Inside Fl_Tree::handle(), calls like this:
> 
>               select_only(_item_focus);
> 
>       ..should really be changed to this:
> 
>               select_only(_item_focus, when());
> 
>       I've submitted STR #2807 on your behalf:
>         http://fltk.org/str.php?L2807
>       Should be fixed in the next update to 1.3.
> 
>       I'll try to post a patch for SVN which you can use
>       to fix Fl_Tree to support FL_WHEN_NEVER properly.
> 
>       There really should be an easier way to allow callback()
>       to handle multi-clicks more easily than having to derive
>       from Fl_Tree and override handle().
> 
>       I should probably implement an FL_TREE_REASON_CLICKED
>       so that any click events on an item can be detected,
>       instead of just select/deselect/open/closed events.
> 
>       Regarding detecting double-clicks on items, I think you
>       should be able to something like this for now:
> 
> #include <stdio.h>
> #include <FL/Fl.H>
> #include <FL/Fl_Double_Window.H>
> #include <FL/Fl_Tree.H>
> //
> // Detecting double-click on Fl_Tree item for 1.3.0.
> // erco 1.0 02/20/2012
> //
> class MyTree : public Fl_Tree {
> public:
>     MyTree(int X,int Y,int W,int H,const char*L=0) : Fl_Tree(X,Y,W,H,L) { }
>     int handle(int e) {
>         if ( e == FL_PUSH ) {                             // Mouse click?
>             const Fl_Tree_Item *item = find_clicked();    // item clicked
>             if ( item ) {                                 // valid item?
>                 callback_item((Fl_Tree_Item*)item);     // set callback item
>                 callback_reason(FL_TREE_REASON_SELECTED); // set callback 
> reason
>                 do_callback();
>             }
>         }
>         return(Fl_Tree::handle(e));
>     }
> };
> void TreeCallback(Fl_Widget *w, void *data) {
>   Fl_Tree *tree = (Fl_Tree*)w;
>   Fl_Tree_Item *item = (Fl_Tree_Item*)tree->callback_item();
>   if ( ! item ) return;
>   switch ( tree->callback_reason() ) {
>     case FL_TREE_REASON_SELECTED: {
>       if ( Fl::event_clicks() == 1 ) {
>           fprintf(stderr, "Item '%s' double clicked\n", item->label());
>       }
>       break;
>     }
>     default:
>       break;
>   }
> }
> int main(int argc, char *argv[]) {
>   Fl_Double_Window *win = new Fl_Double_Window(250, 400, "Simple Tree");
>   win->begin();
>     // Create the tree
>     MyTree *tree = new MyTree(10, 10, win->w()-20, win->h()-20);
>     tree->showroot(0);
>     tree->callback(TreeCallback);
>     // Add some items
>     tree->add("Flintstones/Fred");
>     tree->add("Flintstones/Wilma");
>     tree->add("Flintstones/Pebbles");
>     tree->add("Simpsons/Homer");
>     tree->add("Simpsons/Marge");
>     tree->add("Simpsons/Bart");
>     tree->add("Simpsons/Lisa");
>   win->end();
>   win->resizable(win);
>   win->show(argc, argv);
>   return(Fl::run());
> }

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to