This will be a longish one, and probably not interesting to most folk...

> OK - I was going to suggest that popping up a modal window with an
> Fl_Select_Browser in it would probably do the trick, but if you have it
> working already then that's good.

I thought I posted this earlier, but it looks like I forgot... Here's the 
"proof of concept" that I did in my tea-break, for my Fl_Select_Browser based 
pop-up menu system to address Michael's problems with Fl_Menu on his 
touchscreen device.

Just for completeness, or in case any one cares!

---------------
/* Test of a pseudo popup menu based on Fl_Select_Browser */

#include <stdio.h>

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Select_Browser.H>

Fl_Double_Window *main_win=(Fl_Double_Window *)0;
Fl_Double_Window *pop_win=(Fl_Double_Window *)0;
Fl_Menu_Bar *mbar=(Fl_Menu_Bar *)0;
Fl_Button *quit_bt=(Fl_Button *)0;
Fl_Button *add_bt=(Fl_Button *)0;
Fl_Button *rmv_bt=(Fl_Button *)0;

static int last_item = 0; // last item we clicked in the popup

/********************************************************************************************/
class Pop_Browser : public Fl_Select_Browser {
    public:
    Pop_Browser(int X, int Y, int W, int H) : Fl_Select_Browser(X, Y, W, H){};

    int get_height(void){return full_height();}
    int get_width(void){return full_width();}
};

Pop_Browser *pop_brws=(Pop_Browser *)0;

/********************************************************************************************/
static void cb_mb_pop(Fl_Menu_*, void*) {
    // menu item pop up
    int fh = pop_brws->get_height();
    int fw = pop_brws->get_width();
    int x1 = Fl::event_x_root();
    int y1 = Fl::event_y_root();
    pop_brws->topline(1); // ensure the browser is always scrolled to the top

    if(fh < 100) fh = 100;
    if(fw < 100) fw = 100;

    fh += 8; // 4 for browser border + 4 for window border
    fw += 20;
    pop_win->resize(x1, y1, fw, fh);
    pop_win->show();
}

/********************************************************************************************/
static void generic_test_cb(Fl_Widget*, void *v) {
    int data = (int)v;
    printf("%s (%d)\n", pop_brws->text(data), data);
}

/********************************************************************************************/
static void cb_quit_bt(Fl_Button*, void*) {
  if(pop_win) pop_win->hide();
  if(main_win) main_win->hide();
}

/********************************************************************************************/
static void cb_add_bt(Fl_Button*, void*) {
    static int incr = 66;
    char line[32];
    sprintf(line, "line: %d", incr);
    pop_brws->add(line, (void *)generic_test_cb);
    incr++;
}

/********************************************************************************************/
static void cb_rmv_bt(Fl_Button*, void*) {
    int max = pop_brws->size();

    if((last_item > 0) || (last_item <= max)) {
        pop_brws->remove(last_item);
        last_item = 0;
    }
}

/********************************************************************************************/
static void cb_pop_brws(Pop_Browser* w, void*) {
    // browser callback
    int val = w->value();
    if(val) {
        Fl_Callback *get_cb = (Fl_Callback*)w->data(val);
        get_cb(NULL, (void*)val);
    } else {
      puts("no select");
    }
    last_item = val;
    fflush(stdout);
    if(pop_win) pop_win->hide();
}

/********************************************************************************************/
Fl_Menu_Item menu_mbar[] = {
 {"popup", 0,  (Fl_Callback*)cb_mb_pop, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

/********************************************************************************************/
int main(int argc, char **argv) {
    main_win = new Fl_Double_Window(404, 271, "Touch Menu Test");
    main_win->begin();

    mbar = new Fl_Menu_Bar(0, 0, 404, 20);
    mbar->box(FL_FLAT_BOX);
    mbar->menu(menu_mbar);

    add_bt = new Fl_Button(105, 215, 64, 30, "Add");
    add_bt->callback((Fl_Callback*)cb_add_bt);

    rmv_bt = new Fl_Button(205, 215, 64, 30, "Remove");
    rmv_bt->callback((Fl_Callback*)cb_rmv_bt);

    quit_bt = new Fl_Button(305, 215, 64, 30, "Quit");
    quit_bt->callback((Fl_Callback*)cb_quit_bt);

    main_win->end();
    main_win->show(argc, argv);

    pop_win = new Fl_Double_Window(350, 350);
    pop_win->begin();
    pop_win->clear_border();
    pop_win->box(FL_THIN_UP_BOX);

    pop_brws = new Pop_Browser(2, 2, 346, 346);
    pop_brws->box(FL_FLAT_BOX);
    pop_brws->color(FL_BACKGROUND_COLOR);
    pop_brws->callback((Fl_Callback*)cb_pop_brws);
    char line[32];
    for(int i = 1; i <= 7; i++) {
        sprintf(line, "line: %d", i);
        pop_brws->add(line, (void *)generic_test_cb);
    }
    pop_brws->add("Menu Entry with a very long title", (void *)generic_test_cb);
    pop_brws->has_scrollbar(0); // supress any scrollbars - we do not want them

    pop_win->resizable(pop_brws);
    pop_win->set_modal();
    pop_win->end();

    return Fl::run();
}

/* end of file */

---------------





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

Reply via email to