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
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk