diff options
| -rw-r--r-- | FL/Fl_File_Chooser.H | 2 | ||||
| -rw-r--r-- | fluid/Fl_Type.h | 2 | ||||
| -rw-r--r-- | fluid/Fluid_Image.cxx | 65 | ||||
| -rw-r--r-- | fluid/Fluid_Image.h | 2 | ||||
| -rw-r--r-- | fluid/code.cxx | 8 | ||||
| -rw-r--r-- | src/Fl_File_Chooser.cxx | 12 | ||||
| -rw-r--r-- | src/Fl_File_Chooser.fl | 9 |
7 files changed, 58 insertions, 42 deletions
diff --git a/FL/Fl_File_Chooser.H b/FL/Fl_File_Chooser.H index 6808c25b1..6e3ed2297 100644 --- a/FL/Fl_File_Chooser.H +++ b/FL/Fl_File_Chooser.H @@ -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]; diff --git a/fluid/Fl_Type.h b/fluid/Fl_Type.h index 0b90cb63b..2a66c5f05 100644 --- a/fluid/Fl_Type.h +++ b/fluid/Fl_Type.h @@ -30,6 +30,7 @@ #include <FL/Fl_Plugin.H> #include "Fluid_Image.h" #include <FL/fl_draw.H> +#include <stdarg.h> void set_modflag(int mf); @@ -813,6 +814,7 @@ int write_declare(const char *, ...) __fl_attr((__format__ (__printf__, 1, 2))); int is_id(char); const char* unique_id(void* o, const char*, const char*, const char*); void write_c(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2))); +void vwrite_c(const char* format, va_list args); void write_h(const char*, ...) __fl_attr((__format__ (__printf__, 1, 2))); void write_cstring(const char *); void write_cstring(const char *,int length); diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx index 6d93d28e0..bbaa423e0 100644 --- a/fluid/Fluid_Image.cxx +++ b/fluid/Fluid_Image.cxx @@ -1,9 +1,9 @@ // // "$Id$" // -// Pixmap label support for the Fast Light Tool Kit (FLTK). +// Pixmap (and other images) label support for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2010 by Bill Spitzak and others. +// Copyright 1998-2015 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -24,10 +24,11 @@ #include <stdio.h> #include <errno.h> #include <stdlib.h> +#include <stdarg.h> #include <FL/filename.H> -extern void goto_source_dir(); // in fluid.C -extern void leave_source_dir(); // in fluid.C +extern void goto_source_dir(); // in fluid.cxx +extern void leave_source_dir(); // in fluid.cxx void Fluid_Image::image(Fl_Widget *o) { if (o->window() != o) o->image(img); @@ -44,6 +45,8 @@ static int jpeg_header_written = 0; void Fluid_Image::write_static() { if (!img) return; + const char *idata_name = unique_id(this, "idata", fl_filename_name(name()), 0); + function_name_ = unique_id(this, "image", fl_filename_name(name()), 0); if (img->count() > 1) { // Write Pixmap data... write_c("\n"); @@ -51,8 +54,7 @@ void Fluid_Image::write_static() { write_c("#include <FL/Fl_Pixmap.H>\n"); pixmap_header_written = write_number; } - write_c("static const char *%s[] = {\n", - unique_id(this, "idata", fl_filename_name(name()), 0)); + write_c("static const char *%s[] = {\n", idata_name); write_cstring(img->data()[0], strlen(img->data()[0])); int i; @@ -74,9 +76,7 @@ void Fluid_Image::write_static() { write_cstring(img->data()[i], img->w() * chars_per_color); } write_c("\n};\n"); - write_c("static Fl_Pixmap %s(%s);\n", - unique_id(this, "image", fl_filename_name(name()), 0), - unique_id(this, "idata", fl_filename_name(name()), 0)); + write_initializer("Fl_Pixmap", "%s", idata_name); } else if (img->d() == 0) { // Write Bitmap data... write_c("\n"); @@ -84,14 +84,10 @@ void Fluid_Image::write_static() { write_c("#include <FL/Fl_Bitmap.H>\n"); bitmap_header_written = write_number; } - write_c("static const unsigned char %s[] =\n", - unique_id(this, "idata", fl_filename_name(name()), 0)); + write_c("static const unsigned char %s[] =\n", idata_name); write_cdata(img->data()[0], ((img->w() + 7) / 8) * img->h()); write_c(";\n"); - write_c("static Fl_Bitmap %s(%s, %d, %d);\n", - unique_id(this, "image", fl_filename_name(name()), 0), - unique_id(this, "idata", fl_filename_name(name()), 0), - img->w(), img->h()); + write_initializer( "Fl_Bitmap", "%s, %d, %d", idata_name, img->w(), img->h()); } else if (strcmp(fl_filename_ext(name()), ".jpg")==0) { // Write jpeg image data... write_c("\n"); @@ -99,8 +95,7 @@ void Fluid_Image::write_static() { write_c("#include <FL/Fl_JPEG_Image.H>\n"); jpeg_header_written = write_number; } - write_c("static const unsigned char %s[] =\n", - unique_id(this, "idata", fl_filename_name(name()), 0)); + write_c("static const unsigned char %s[] =\n", idata_name); FILE *f = fl_fopen(name(), "rb"); if (!f) { @@ -119,32 +114,39 @@ void Fluid_Image::write_static() { } write_c(";\n"); - write_c("static Fl_JPEG_Image %s(\"%s\", %s);\n", - unique_id(this, "image", fl_filename_name(name()), 0), - fl_filename_name(name()), - unique_id(this, "idata", fl_filename_name(name()), 0)); + write_initializer("Fl_JPEG_Image", "\"%s\", %s", fl_filename_name(name()), idata_name); } else { // Write image data... write_c("\n"); if (image_header_written != write_number) { write_c("#include <FL/Fl_Image.H>\n"); image_header_written = write_number; - } - write_c("static const unsigned char %s[] =\n", - unique_id(this, "idata", fl_filename_name(name()), 0)); + } + write_c("static const unsigned char %s[] =\n", idata_name); write_cdata(img->data()[0], (img->w() * img->d() + img->ld()) * img->h()); write_c(";\n"); - write_c("static Fl_RGB_Image %s(%s, %d, %d, %d, %d);\n", - unique_id(this, "image", fl_filename_name(name()), 0), - unique_id(this, "idata", fl_filename_name(name()), 0), - img->w(), img->h(), img->d(), img->ld()); + write_initializer("Fl_RGB_Image", "%s, %d, %d, %d, %d", idata_name, img->w(), img->h(), img->d(), img->ld()); } } +void Fluid_Image::write_initializer(const char *type_name, const char *format, ...) { + /* Outputs code that returns (and initializes if needed) an Fl_Image as follows: + static Fl_Image *'function_name_'() { + static Fl_Image *image = new 'type_name'('product of format and remaining args'); + return image; + } */ + va_list ap; + va_start(ap, format); + write_c("static Fl_Image *%s() {\n static Fl_Image *image = new %s(", function_name_, type_name); + vwrite_c(format, ap); + write_c(");\n return image;\n}\n"); + va_end(ap); +} + void Fluid_Image::write_code(const char *var, int inactive) { - if (!img) return; - write_c("%s%s->%s(%s);\n", indent(), var, inactive ? "deimage" : "image", - unique_id(this, "image", fl_filename_name(name()), 0)); + /* Outputs code that attaches an image to an Fl_Widget or Fl_Menu_Item. + This code calls a function output before by Fluid_Image::write_initializer() */ + if (img) write_c("%s%s->%s( %s() );\n", indent(), var, inactive ? "deimage" : "image", function_name_); } @@ -207,6 +209,7 @@ Fluid_Image::Fluid_Image(const char *iname) { written = 0; refcount = 0; img = Fl_Shared_Image::get(iname); + function_name_ = NULL; } void Fluid_Image::increment() { diff --git a/fluid/Fluid_Image.h b/fluid/Fluid_Image.h index 7e8cfd53c..f36ec2b1e 100644 --- a/fluid/Fluid_Image.h +++ b/fluid/Fluid_Image.h @@ -30,6 +30,7 @@ class Fluid_Image { const char *name_; int refcount; Fl_Shared_Image *img; + const char *function_name_; protected: Fluid_Image(const char *name); // no public constructor ~Fluid_Image(); // no public destructor @@ -41,6 +42,7 @@ public: void image(Fl_Widget *); // set the image of this widget void deimage(Fl_Widget *); // set the deimage of this widget void write_static(); + void write_initializer(const char *type_name, const char *format, ...); void write_code(const char *var, int inactive = 0); const char *name() const {return name_;} }; diff --git a/fluid/code.cxx b/fluid/code.cxx index 10d62cdf5..02cc439bc 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -254,14 +254,18 @@ void write_cdata(const char *s, int length) { putc('}', code_file); } -void write_c(const char* format,...) { +void vwrite_c(const char* format, va_list args) { if (varused_test) { varused = 1; return; } + vfprintf(code_file, format, args); +} + +void write_c(const char* format,...) { va_list args; va_start(args, format); - vfprintf(code_file, format, args); + vwrite_c(format, args); va_end(args); } diff --git a/src/Fl_File_Chooser.cxx b/src/Fl_File_Chooser.cxx index c5288e92a..e5274cb51 100644 --- a/src/Fl_File_Chooser.cxx +++ b/src/Fl_File_Chooser.cxx @@ -27,7 +27,6 @@ #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(""); @@ -60,9 +59,14 @@ 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_Image *image_new() { + static Fl_Image *image = new Fl_Bitmap(idata_new, 16, 16); + return image; +} void Fl_File_Chooser::cb__i(Fl_Tile*, void*) { update_preview(); @@ -163,10 +167,8 @@ 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) { + if (!prefs_) { 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"); @@ -186,7 +188,7 @@ Fl_File_Chooser::Fl_File_Chooser(const char *d, const char *p, int t, const char favoritesButton->label(favorites_label); } // Fl_Menu_Button* favoritesButton { Fl_Button* o = newButton = new Fl_Button(455, 10, 25, 25); - newButton->image(image_new); + newButton->image( image_new() ); newButton->labelsize(8); newButton->callback((Fl_Callback*)cb_newButton); o->tooltip(new_directory_tooltip); diff --git a/src/Fl_File_Chooser.fl b/src/Fl_File_Chooser.fl index c7332a776..c0940be94 100644 --- a/src/Fl_File_Chooser.fl +++ b/src/Fl_File_Chooser.fl @@ -36,7 +36,7 @@ class FL_EXPORT Fl_File_Chooser {open } { decl {enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };} {public local } - decl {static Fl_Preferences prefs_;} {private local + decl {static Fl_Preferences *prefs_;} {private local } decl {void (*callback_)(Fl_File_Chooser*, void *);} {private local } @@ -69,6 +69,9 @@ class FL_EXPORT Fl_File_Chooser {open decl {void update_preview();} {private local } Function {Fl_File_Chooser(const char *d, const char *p, int t, const char *title)} {} { + code {if (!prefs_) { + prefs_ = new Fl_Preferences(Fl_Preferences::USER, "fltk.org", "filechooser"); +}} {} code {Fl_Group *prev_current = Fl_Group::current();} {} Fl_Window window { label {Choose File} @@ -238,7 +241,7 @@ update_favorites(); value(d); type(t); int e; -prefs_.get("preview", e, 1); +prefs_->get("preview", e, 1); preview(e); Fl_Group::current(prev_current);} {} code {ext_group=(Fl_Widget*)0;} {} @@ -307,7 +310,7 @@ showChoiceCB();} {} } Function {ok_label(const char *l)} {return_type void } { - code {okButton->label(l); + code {if (l) okButton->label(l); int w=0, h=0; okButton->measure_label(w, h); okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(), |
