Allowing to use FLTK objects in static initializers (cont'd).
For fl_file_chooser() and Fl_File_Chooser objects. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10961 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
6bdb661c2a
commit
cf14f77a90
@ -49,7 +49,7 @@ class FL_EXPORT Fl_File_Chooser {
|
||||
public:
|
||||
enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };
|
||||
private:
|
||||
static Fl_Preferences prefs_;
|
||||
static Fl_Preferences *prefs_;
|
||||
void (*callback_)(Fl_File_Chooser*, void *);
|
||||
void *data_;
|
||||
char directory_[FL_PATH_MAX];
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
|
||||
#include "../FL/Fl_File_Chooser.H"
|
||||
#include <FL/fl_draw.H>
|
||||
#include <FL/Fl_Bitmap.H>
|
||||
|
||||
void Fl_File_Chooser::cb_window_i(Fl_Double_Window*, void*) {
|
||||
fileName->value("");
|
||||
@ -59,11 +60,9 @@ void Fl_File_Chooser::cb_newButton(Fl_Button* o, void* v) {
|
||||
((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_newButton_i(o,v);
|
||||
}
|
||||
|
||||
#include <FL/Fl_Bitmap.H>
|
||||
static const unsigned char idata_new[] =
|
||||
{0,0,120,0,132,0,2,1,1,254,1,128,49,128,49,128,253,128,253,128,49,128,49,
|
||||
128,1,128,1,128,255,255,0,0};
|
||||
static Fl_Bitmap image_new(idata_new, 16, 16);
|
||||
|
||||
void Fl_File_Chooser::cb__i(Fl_Tile*, void*) {
|
||||
update_preview();
|
||||
@ -164,6 +163,11 @@ void Fl_File_Chooser::cb_favOkButton(Fl_Return_Button* o, void* v) {
|
||||
}
|
||||
|
||||
Fl_File_Chooser::Fl_File_Chooser(const char *d, const char *p, int t, const char *title) {
|
||||
static Fl_Bitmap *image_new = NULL;
|
||||
if (!image_new) {
|
||||
prefs_ = new Fl_Preferences(Fl_Preferences::USER, "fltk.org", "filechooser");
|
||||
image_new = new Fl_Bitmap(idata_new, 16, 16);
|
||||
}
|
||||
Fl_Group *prev_current = Fl_Group::current();
|
||||
{ window = new Fl_Double_Window(490, 380, "Choose File");
|
||||
window->callback((Fl_Callback*)cb_window, (void*)(this));
|
||||
@ -305,7 +309,7 @@ Fl_File_Chooser::Fl_File_Chooser(const char *d, const char *p, int t, const char
|
||||
value(d);
|
||||
type(t);
|
||||
int e;
|
||||
prefs_.get("preview", e, 1);
|
||||
prefs_->get("preview", e, 1);
|
||||
preview(e);
|
||||
Fl_Group::current(prev_current);
|
||||
ext_group=(Fl_Widget*)0;
|
||||
@ -369,7 +373,7 @@ const char * Fl_File_Chooser::label() {
|
||||
}
|
||||
|
||||
void Fl_File_Chooser::ok_label(const char *l) {
|
||||
okButton->label(l);
|
||||
if (l) okButton->label(l);
|
||||
int w=0, h=0;
|
||||
okButton->measure_label(w, h);
|
||||
okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
|
||||
|
||||
@ -379,7 +379,7 @@
|
||||
// File chooser label strings and sort function...
|
||||
//
|
||||
|
||||
Fl_Preferences Fl_File_Chooser::prefs_(Fl_Preferences::USER, "fltk.org", "filechooser");
|
||||
Fl_Preferences* Fl_File_Chooser::prefs_ = NULL;
|
||||
|
||||
const char *Fl_File_Chooser::add_favorites_label = "Add to Favorites";
|
||||
const char *Fl_File_Chooser::all_files_label = "All Files (*)";
|
||||
@ -546,8 +546,8 @@ Fl_File_Chooser::favoritesButtonCB()
|
||||
|
||||
sprintf(menuname, "favorite%02d", v);
|
||||
|
||||
prefs_.set(menuname, directory_);
|
||||
prefs_.flush();
|
||||
prefs_->set(menuname, directory_);
|
||||
prefs_->flush();
|
||||
|
||||
quote_pathname(menuname, directory_, sizeof(menuname));
|
||||
favoritesButton->add(menuname);
|
||||
@ -590,7 +590,7 @@ Fl_File_Chooser::favoritesCB(Fl_Widget *w)
|
||||
// Get favorite directory 0 to 99...
|
||||
sprintf(name, "favorite%02d", i);
|
||||
|
||||
prefs_.get(name, pathname, "", sizeof(pathname));
|
||||
prefs_->get(name, pathname, "", sizeof(pathname));
|
||||
|
||||
// Stop on the first empty favorite...
|
||||
if (!pathname[0]) break;
|
||||
@ -669,7 +669,7 @@ Fl_File_Chooser::favoritesCB(Fl_Widget *w)
|
||||
// Set favorite directory 0 to 99...
|
||||
sprintf(name, "favorite%02d", i);
|
||||
|
||||
prefs_.set(name, favList->text(i + 1));
|
||||
prefs_->set(name, favList->text(i + 1));
|
||||
}
|
||||
|
||||
// Clear old entries as necessary...
|
||||
@ -677,14 +677,14 @@ Fl_File_Chooser::favoritesCB(Fl_Widget *w)
|
||||
// Clear favorite directory 0 to 99...
|
||||
sprintf(name, "favorite%02d", i);
|
||||
|
||||
prefs_.get(name, pathname, "", sizeof(pathname));
|
||||
prefs_->get(name, pathname, "", sizeof(pathname));
|
||||
|
||||
if (pathname[0]) prefs_.set(name, "");
|
||||
if (pathname[0]) prefs_->set(name, "");
|
||||
else break;
|
||||
}
|
||||
|
||||
update_favorites();
|
||||
prefs_.flush();
|
||||
prefs_->flush();
|
||||
|
||||
favWindow->hide();
|
||||
}
|
||||
@ -1097,8 +1097,8 @@ Fl_File_Chooser::newdir()
|
||||
void Fl_File_Chooser::preview(int e)
|
||||
{
|
||||
previewButton->value(e);
|
||||
prefs_.set("preview", e);
|
||||
prefs_.flush();
|
||||
prefs_->set("preview", e);
|
||||
prefs_->flush();
|
||||
|
||||
Fl_Group *p = previewBox->parent();
|
||||
if (e) {
|
||||
@ -1283,7 +1283,7 @@ Fl_File_Chooser::update_favorites()
|
||||
|
||||
for (i = 0; i < 100; i ++) {
|
||||
sprintf(menuname, "favorite%02d", i);
|
||||
prefs_.get(menuname, pathname, "", sizeof(pathname));
|
||||
prefs_->get(menuname, pathname, "", sizeof(pathname));
|
||||
if (!pathname[0]) break;
|
||||
|
||||
quote_pathname(menuname, pathname, sizeof(menuname));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user