Re: [fltk.general] Fl_Tree events
Thanks! I missed the find_clicked() method, so I thought it would be more complicated than that to add event checking for that. Also thank you for the code example, it'll help me speed up the creation of what I need =) On 05/17/12 20:27, Greg Ercolano wrote: On 05/17/12 11:56, Eugenio Bargiacchi wrote: What do you suggest as a workaround for me while waiting on the next awesome release? Is the Fl_Button method the only way? I'd suggest derive your own class from Fl_Tree, and make a handle() method catch FL_PUSH and check for the right mouse, and if so, determine the item and then Fl_Tree::select() it, eg: int handle(int e) { switch (e) { case FL_PUSH: if ( Fl::event_button() == FL_RIGHT_MOUSE ) { Fl_Tree_Item *item = (Fl_Tree_Item*)find_clicked(); if ( item ) { printf(*Right* click on item '%s'\n, item-label()); select(item); // for example, select the item } } break; } return(Fl_Tree::handle(e)); } Your tree callback can then check if Fl::event_button() is FL_RIGHT_MOUSE and act accordingly. Oh, and I should have mentioned calling select(item) in the above triggers your tree callback, which is why you can then add the code you want to the tree callback. Here's a compilable example using the above technique to show how it enables right clicking to eg. select items, and how to have your tree callback detect right clicks (see the ** RIGHT MOUSE ** message): #include stdio.h #include FL/Fl.H #include FL/Fl_Double_Window.H #include FL/Fl_Tree.H #include FL/Fl_Menu_Button.H 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) { switch (e) { case FL_PUSH: if ( Fl::event_button() == FL_RIGHT_MOUSE ) { Fl_Tree_Item *item = (Fl_Tree_Item*)find_clicked(); if ( item ) { printf(*Right* click on item '%s'\n, item-label()); select(item); // for example, select the item } } break; } return(Fl_Tree::handle(e)); } }; // Tree's callback //Invoked whenever an item's state changes. // void Tree_CB(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: { char pathname[256]; tree-item_pathname(pathname, sizeof(pathname), item); if ( Fl::event_button() == FL_RIGHT_MOUSE ) { fprintf(stderr, ** RIGHT MOUSE **: ); } fprintf(stderr, Tree_CB: Item selected='%s', Full pathname='%s'\n, item-label(), pathname); break; } case FL_TREE_REASON_DESELECTED: fprintf(stderr, Tree_CB: Item '%s' deselected\n, item-label()); break; case FL_TREE_REASON_OPENED: fprintf(stderr, Tree_CB: Item '%s' opened\n, item-label()); break; case FL_TREE_REASON_CLOSED: fprintf(stderr, Tree_CB: Item '%s' closed\n, item-label()); default: break; } } int main(int argc, char *argv[]) { Fl_Double_Window win(250, 400, Simple Tree); MyTree tree(10, 10, win.w()-20, win.h()-20); tree.callback(Tree_CB); tree.add(Aaa/a-0001); tree.add(Aaa/a-0002); tree.add(Aaa/a-0003); tree.add(Bbb/b-0001); tree.add(Bbb/b-0002); tree.add(Bbb/b-0003); tree.end(); win.end(); win.resizable(win); win.show(argc, argv); return(Fl::run()); } ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
[fltk.general] Fl_Tree events
I'm trying to intercept right click events on a Fl_Tree, and do different actions depending on the Fl_Tree_Item selected this way. I've noticed that in the handle code of Fl_Tree a right click sets the corresponding Fl_Tree_Item as the local focus, but does not select it nor triggers a callback. The problem is even if I were to reimplement handle() and make it trigger a callback, there would be no obvious way for me to get the focused item, since the pointer that holds that is private ( Fl::focus() only returns the Fl_Tree itself ), and I saw no method to recover it. A possibility would be using a Fl_Button with no box ( otherwise it looks terrible ) for each item, and in their callback check if the mouse button clicked is left or right. However one would need to directly click the ( boxless ) button to trigger its event, while right-clicking on the very far left of the element still focuses it ( and would not trigger the button ). I think this would give a strange feedback to the user, since visually he clicked it but nothing happened. And another problem of buttons as Fl_Tree_Items is that the text is not aligned perfectly, and looks odd with normal items. Is there a straightforward way to do something like this? Thanks in advance. ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Fl_Tree events
On 05/17/12 09:44, Eugenio Bargiacchi wrote: The problem is even if I were to reimplement handle() and make it trigger a callback, there would be no obvious way for me to get the focused item, since the pointer that holds that is private It looks like the Fl_Tree API has a public set_item_focus(), but does not have a get_item_focus(). Would having that help you? If so, I suggest adding one to the Fl_Tree.H file, and if it helps you, follow up and I'll add it to 1.3.x. Fl_Tree is fairly young, so it's in active development, and we're finding lots of new things to add to it. ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Fl_Tree events
get_item_focus() would certainly help. If I may suggest, you could also add FL_TREE_REASON_FOCUS_SELECTED and FL_TREE_REASON_FOCUS_DESELECTED as fields in the Fl_Tree_Reason enum, if the focus changed but the selected item did not. And maybe a couple of methods to setup which key/click triggers a focus change or a select change =) What do you suggest as a workaround for me while waiting on the next awesome release? Is the Fl_Button method the only way? Many thanks! On 05/17/12 09:44, Eugenio Bargiacchi wrote: The problem is even if I were to reimplement handle() and make it trigger a callback, there would be no obvious way for me to get the focused item, since the pointer that holds that is private It looks like the Fl_Tree API has a public set_item_focus(), but does not have a get_item_focus(). Would having that help you? If so, I suggest adding one to the Fl_Tree.H file, and if it helps you, follow up and I'll add it to 1.3.x. Fl_Tree is fairly young, so it's in active development, and we're finding lots of new things to add to it. ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Fl_Tree events
On 05/17/12 11:56, Eugenio Bargiacchi wrote: get_item_focus() would certainly help. Try implementing it and see if it does. I'll certainly add it anyway, as it seems to be an omission. If I may suggest, you could also add FL_TREE_REASON_FOCUS_SELECTED and FL_TREE_REASON_FOCUS_DESELECTED as fields in the Fl_Tree_Reason enum, if the focus changed but the selected item did not. Sure, can investigate that. And maybe a couple of methods to setup which key/click triggers a focus change or a select change =) I don't think I'd do this with methods, as the default behavior needs to be consistent with other FLTK widgets for focus nav, ie. up/dn/lt/rt are best for this. Rather than clutter up the API with methods to change these, and have to have arrays of key values, I'd rather leave it to the app programmer to derive a class, handle() the events to get the keys they want, and make sure the API provides methods to change focus and change selection (which I think is already there; you have Fl_Tree::set_item_focus() and Fl_Tree::select(item)) What do you suggest as a workaround for me while waiting on the next awesome release? Is the Fl_Button method the only way? I'd suggest derive your own class from Fl_Tree, and make a handle() method catch FL_PUSH and check for the right mouse, and if so, determine the item and then Fl_Tree::select() it, eg: int handle(int e) { switch (e) { case FL_PUSH: if ( Fl::event_button() == FL_RIGHT_MOUSE ) { Fl_Tree_Item *item = (Fl_Tree_Item*)find_clicked(); if ( item ) { printf(*Right* click on item '%s'\n, item-label()); select(item); // for example, select the item } } break; } return(Fl_Tree::handle(e)); } Your tree callback can then check if Fl::event_button() is FL_RIGHT_MOUSE and act accordingly. Or, just put the handling code in the above handle method. Many thanks! On 05/17/12 09:44, Eugenio Bargiacchi wrote: The problem is even if I were to reimplement handle() and make it trigger a callback, there would be no obvious way for me to get the focused item, since the pointer that holds that is private It looks like the Fl_Tree API has a public set_item_focus(), but does not have a get_item_focus(). Would having that help you? If so, I suggest adding one to the Fl_Tree.H file, and if it helps you, follow up and I'll add it to 1.3.x. Fl_Tree is fairly young, so it's in active development, and we're finding lots of new things to add to it. ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk