Fl_Check_Browser callback does not get called.

38 views
Skip to first unread message

aditya...@gmail.com

unread,
Jun 13, 2021, 12:17:21 PM6/13/21
to fltk.general

Hi,
It seems like `Fl_Check_Browser`'s callback doesn't get called when items are selected and deselected. I tried the example program compiled with the last FLTK commit (#986a8b33a2b5e503dd36ddbc8283d489ebbd9290) below with both keyboard and mouse input:

#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Check_Browser.H>

void CB(Fl_Widget*, void *) {
  puts("In the callback");
}

int main(int argc, char *argv[]) {
  Fl::scheme("gtk+");
  Fl_Double_Window *win = new Fl_Double_Window(250, 120, "Simple Browser");
  win->begin();
  {
    {
      Fl_Check_Browser *brow = new Fl_Check_Browser(10, 10, win->w()-20, 80, "Check");
      brow->callback(CB);
      brow->add("Aaa");
      brow->add("Bbb");
      brow->add("Ccc");
      brow->add("Ddd");
      brow->checked(1,1);
      brow->checked(2,1);
    }
  }
  win->end();
  win->resizable(win);
  win->show(argc, argv);
  return(Fl::run());
}


Albrecht Schlosser

unread,
Jun 13, 2021, 5:35:16 PM6/13/21
to fltkg...@googlegroups.com
On 6/13/21 6:17 PM aditya...@gmail.com wrote:
Hi,
It seems like `Fl_Check_Browser`'s callback doesn't get called when items are selected and deselected. I tried the example program compiled with the last FLTK commit (#986a8b33a2b5e503dd36ddbc8283d489ebbd9290) below with both keyboard and mouse input:

This is correct although AFAICT undocumented. The default when() condition of Fl_Check_Browser is FL_WHEN_NEVER which obviously does not call the callback. I can't tell why this is so, but I believe this should be documented. It's obviously unexpected behavior.

See comment below to make the program do what you (seem to) expect.


#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Check_Browser.H>

void CB(Fl_Widget*, void *) {
  puts("In the callback");
}

int main(int argc, char *argv[]) {
  Fl::scheme("gtk+");
  Fl_Double_Window *win = new Fl_Double_Window(250, 120, "Simple Browser");
  win->begin();
  {
    {
      Fl_Check_Browser *brow = new Fl_Check_Browser(10, 10, win->w()-20, 80, "Check");
      brow->callback(CB);

// add here:

brow->when(FL_WHEN_CHANGED);

Ian MacArthur

unread,
Jun 13, 2021, 5:58:36 PM6/13/21
to 'Phil' via fltk.general
On 13 Jun 2021, at 22:35, Albrecht Schlosser wrote:
>
> This is correct although AFAICT undocumented. The default when() condition of Fl_Check_Browser is FL_WHEN_NEVER which obviously does not call the callback. I can't tell why this is so, but I believe this should be documented.


I think (but do not know) that the idea is so that you can select multiple items *then* trigger whatever action is wanted, rather than have the action trigger on each selection... Maybe...


aditya...@gmail.com

unread,
Jun 14, 2021, 8:05:40 AM6/14/21
to fltk.general
This makes sense and setting it to FL_WHEN_CHANGED worked but it definitely wasn't what I was expecting. I had completely forgotten about FL_WHEN because I've never had to use it, I'll remember to check for that in the future. :)
Reply all
Reply to author
Forward
0 new messages