GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Apr-2005, 12:27
maveganzones's Avatar
maveganzones maveganzones is offline
New Member
 
Join Date: Mar 2005
Location: San Sebastian (Spain)
Posts: 12
maveganzones is on a distinguished road

Using the FL_File_Chooser widget


Hi all, this widget its wonderfull but hard to use. This is how i use it and what problems i havent fixed.

CPP / C++ / C Code:
// The FL_File_Chooser is a subclass of Fl_Group so it can be used like the Fl_Group.
Fl_File_Chooser* fc = new Fl_File_Chooser(".","Image Files (*.{bmp,gif,jpg,png})",Fl_File_Chooser::SINGLE,"Imagen:");
fc->callback(cb_fc);

// ...

// Now the callback
void cb_fc(Fl_File_Chooser* o, void* v) {
// your code
String filename = o -> value();
}

Problem 1: Fl_File_Chooser dosn't implement end() or parent() methods so you can't call the parent from the static callback. This restringes a lot the use of the widget.
Solution: making the parent singleton.

Problem 2: the callback event gets up when you select a file in the browser. This is a little weird. The normal use its to do something when the user push the OK button.
Solution 2: i dont know yet. I dont know how to do it.

The FLTK documentation gives some guidelines to create the Fl_File_Chooser object because the constructor its different from the rest. Take a look at it.

Can anyone give a response to the problem two?

Greetings.
  #2  
Old 08-Apr-2005, 12:07
maveganzones's Avatar
maveganzones maveganzones is offline
New Member
 
Join Date: Mar 2005
Location: San Sebastian (Spain)
Posts: 12
maveganzones is on a distinguished road
In adition to problem 1: i have read in another http://www.gidforums.com/t-4743.html that the void *v param in the callback can convert to the class containing the widget (this is valid for all the widgets not only the Fl_File_Chooser):

CPP / C++ / C Code:
//the callback associated to a widget
void cb_fc(Fl_File_Chooser* o, void* v) {
// your code cant use the class methods and variables
((TheClass*)v)->callback(o); // calling a method of your class
}

void TheClass::callback(Fl_File_Chooser* o) {
//do whatever
String filename = o -> value(); //using the file name
...
}

Now I dont need the singleton pattern to make it works.
  #3  
Old 14-Apr-2005, 17:58
Dimas Dimas is offline
New Member
 
Join Date: Apr 2005
Location: Brasil
Posts: 1
Dimas is on a distinguished road

About problem 2


Quote:
Originally Posted by maveganzones
Hi all, this widget its wonderfull but hard to use. This is how i use it and what problems i havent fixed.

Problem 2: the callback event gets up when you select a file in the browser. This is a little weird. The normal use its to do something when the user push the OK button.
Solution 2: i dont know yet. I dont know how to do it.

I had the same problem, I mean, I wanted to do something only when OK button was pressed! What I did:

CPP / C++ / C Code:
// The FL_File_Chooser is a subclass of Fl_Group so it can be used like the Fl_Group.
Fl_File_Chooser* fc = new Fl_File_Chooser(".","Image Files (*.{bmp,gif,jpg,png})",Fl_File_Chooser::SINGLE,"Imagen:");

// Maybe you don't want to have a file_chooser callback
/*  
fc->callback(cb_fc);

// ...


// Now the callback
void cb_fc(Fl_File_Chooser* o, void* v) {
// your code 
String filename = o -> value();
}
*/

// ....

// Now call the file chooser ...
fc->show();
// ... them make FL wait until the file selection is done
while(fc->shown())
      Fl::wait();
// finally manipulate the file name
String filename = fc -> value();

Hope it works for your problem.
  #4  
Old 18-Apr-2005, 10:48
maveganzones's Avatar
maveganzones maveganzones is offline
New Member
 
Join Date: Mar 2005
Location: San Sebastian (Spain)
Posts: 12
maveganzones is on a distinguished road
it works really good, thx
 
 

Recent GIDBlogWriting a book by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
widget coordinate relative to parent ? Marius Giurgi FLTK Forum 10 10-Mar-2005 07:21
How to refresh a widget immediately dsmith FLTK Forum 8 11-Dec-2004 01:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:53.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.