On 06/03/11 23:53, Greg Ercolano wrote:
> On 06/03/11 18:00, anon wrote:
>> I'm struggling to find out how I can have a Fl_File_Browser
>> that actually selects items when clicked on.
> 
>       It sounds like you want Fl_File_Chooser..


        ..but if you really want Fl_File_Browser,
        this seems to work for selection:


#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_File_Browser.H>
// Demonstrate simple use of Fl_File_Browser with selection -- erco 6/4/11
int main(int argc, char **argv) {
  Fl_Double_Window win(300, 400, "File Browser");
    Fl_File_Browser fbrow(10,10,300-20,400-20);
    fbrow.load(".");
    fbrow.type(FL_HOLD_BROWSER);        // use for single selection
    //fbrow.type(FL_MULTI_BROWSER);     // use for multiple selection
  win.end();
  win.resizable(fbrow);
  win.show(argc,argv);
  return(Fl::run());
}

         To determine what was selected, you can use the usual
         Fl_Browser technique of setting a callback(), and using
         value() and text(value()) to determine the item.


#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_File_Browser.H>
#include <FL/fl_ask.H>
// Demonstrate Fl_File_Browser with callback -- erco 6/4/11
void BrowserCallback(Fl_Widget *w, void *data) {
  Fl_File_Browser *fbrow = (Fl_File_Browser*)w;
  int index = fbrow->value();
  if ( index > 0 ) {
    fl_alert("Selected: %d (%s)\n", index, fbrow->text(index));
  } else {
    fl_alert("Selected: %d (???)\n", index);
  }
}
int main(int argc, char **argv) {
  Fl_Double_Window win(300, 400, "File Browser");
    Fl_File_Browser fbrow(10,10,300-20,400-20);
    fbrow.load(".");
    fbrow.type(FL_HOLD_BROWSER);
    fbrow.callback(BrowserCallback);
  win.end();
  win.resizable(fbrow);
  win.show(argc,argv);
  return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to