diff options
Diffstat (limited to 'fluid/app')
| -rw-r--r-- | fluid/app/Image_Asset.cxx | 23 | ||||
| -rw-r--r-- | fluid/app/Image_Asset.h | 12 | ||||
| -rw-r--r-- | fluid/app/Snap_Action.cxx | 22 | ||||
| -rw-r--r-- | fluid/app/Snap_Action.h | 8 |
4 files changed, 35 insertions, 30 deletions
diff --git a/fluid/app/Image_Asset.cxx b/fluid/app/Image_Asset.cxx index cea3cc058..36fa4d443 100644 --- a/fluid/app/Image_Asset.cxx +++ b/fluid/app/Image_Asset.cxx @@ -39,7 +39,6 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> -#include <string> /** Simple string-to-Image_Asset map entry */ struct Image_Asset_Entry { @@ -210,7 +209,8 @@ void Image_Asset::write_static_rgb(fld::io::Code_Writer& f, const char* idata_na void Image_Asset::write_static(fld::io::Code_Writer& f, int compressed) { if (!image_) return; const char *idata_name = f.unique_id(this, "idata", fl_filename_name(filename()), 0); - initializer_function_ = f.unique_id(this, "image", fl_filename_name(filename()), 0); + if (initializer_function_) free(initializer_function_); + initializer_function_ = fl_strdup(f.unique_id(this, "image", fl_filename_name(filename()), 0)); if (is_animated_gif_) { // Write animated gif image data... @@ -370,7 +370,7 @@ void Image_Asset::write_file_error(fld::io::Code_Writer& f, const char *fmt) { void Image_Asset::write_initializer(fld::io::Code_Writer& f, const char *image_class, const char *format, ...) { va_list ap; va_start(ap, format); - f.write_c("static Fl_Image *%s() {\n", initializer_function_.c_str()); + f.write_c("static Fl_Image *%s() {\n", initializer_function_); if (is_animated_gif_) f.write_c("%sFl_GIF_Image::animate = true;\n", f.indent(1)); f.write_c("%sstatic Fl_Image *image = 0L;\n", f.indent(1)); @@ -402,11 +402,11 @@ void Image_Asset::write_code(fld::io::Code_Writer& f, int bind, const char *var, var, bind ? "bind_" : "", inactive ? "deimage" : "image", - initializer_function_.c_str()); + initializer_function_); if (is_animated_gif_) f.write_c("%s((Fl_Anim_GIF_Image*)(%s()))->canvas(%s, Fl_Anim_GIF_Image::DONT_RESIZE_CANVAS);\n", f.indent(), - initializer_function_.c_str(), + initializer_function_, var); } } @@ -424,7 +424,7 @@ void Image_Asset::write_code(fld::io::Code_Writer& f, int bind, const char *var, void Image_Asset::write_inline(fld::io::Code_Writer& f, int inactive) { (void)inactive; if (image_) { - f.write_c("%s()", initializer_function_.c_str()); + f.write_c("%s()", initializer_function_); } } @@ -492,13 +492,16 @@ Image_Asset* Image_Asset::find(const char *iname) { */ Image_Asset::Image_Asset(const char *iname) { - filename_ = iname; + is_animated_gif_ = 0; + filename_ = iname ? fl_strdup(iname) : 0; + refcount_ = 0; + initializer_function_ = 0; image_ = Fl_Shared_Image::get(iname); if (image_ && iname) { const char *ext = fl_filename_ext(iname); if (fl_ascii_strcasecmp(ext, ".gif")==0) { int fc = Fl_Anim_GIF_Image::frame_count(iname); - if (fc > 0) is_animated_gif_ = true; + if (fc > 0) is_animated_gif_ = 1; } } } @@ -538,8 +541,10 @@ void Image_Asset::dec_ref() { when the object is destroyed. */ Image_Asset::~Image_Asset() { - image_asset_map.erase(filename_.c_str()); + image_asset_map.erase(filename_); if (image_) image_->release(); + if (filename_) free(filename_); + if (initializer_function_) free(initializer_function_); } //////////////////////////////////////////////////////////////// diff --git a/fluid/app/Image_Asset.h b/fluid/app/Image_Asset.h index fcc8fb31c..1d6909a70 100644 --- a/fluid/app/Image_Asset.h +++ b/fluid/app/Image_Asset.h @@ -29,11 +29,11 @@ class Image_Asset { private: // member variables - bool is_animated_gif_ = false; ///< It's an animated gif. - std::string filename_ { }; ///< Relative path to the image file - int refcount_ = 0; ///< Reference count - Fl_Shared_Image *image_ = 0; ///< The actual image as managed by FLTK - std::string initializer_function_ { }; ///< The name of the initializer function + int is_animated_gif_; ///< It's an animated gif. + char *filename_; ///< Relative path to the image file + int refcount_; ///< Reference count + Fl_Shared_Image *image_; ///< The actual image as managed by FLTK + char *initializer_function_; ///< The name of the initializer function private: // methods Image_Asset(const char *name); // no public constructor @@ -52,7 +52,7 @@ public: // methods void write_code(fld::io::Code_Writer& f, int bind, const char *var, int inactive = 0); void write_inline(fld::io::Code_Writer& f, int inactive = 0); void write_file_error(fld::io::Code_Writer& f, const char *fmt); - const char *filename() const { return filename_.c_str(); } + const char *filename() const { return filename_ ? filename_ : ""; } }; // pop up file chooser and return a legal image selected by user, diff --git a/fluid/app/Snap_Action.cxx b/fluid/app/Snap_Action.cxx index 51cdb9817..2e30853d4 100644 --- a/fluid/app/Snap_Action.cxx +++ b/fluid/app/Snap_Action.cxx @@ -38,6 +38,7 @@ #define MAX(a,b) ((a)>=(b) ? (a) : (b)) #endif + using namespace fld; using namespace fld::app; @@ -663,9 +664,9 @@ void Layout_List::update_menu_labels() { /** Load all user layouts from the FLUID user preferences. */ -int Layout_List::load(const std::string &filename) { +int Layout_List::load(const char *filename) { remove_all(FLD_TOOL_STORE_FILE); - Fl_Preferences prefs(filename.c_str(), "layout.fluid.fltk.org", 0, Fl_Preferences::C_LOCALE); + Fl_Preferences prefs(filename, "layout.fluid.fltk.org", 0, Fl_Preferences::C_LOCALE); read(prefs, FLD_TOOL_STORE_FILE); return 0; } @@ -673,9 +674,9 @@ int Layout_List::load(const std::string &filename) { /** Save all user layouts to the FLUID user preferences. */ -int Layout_List::save(const std::string &filename) { +int Layout_List::save(const char *filename) { assert(this); - Fl_Preferences prefs(filename.c_str(), "layout.fluid.fltk.org", 0, (Fl_Preferences::Root)(Fl_Preferences::C_LOCALE|Fl_Preferences::CLEAR)); + Fl_Preferences prefs(filename, "layout.fluid.fltk.org", 0, (Fl_Preferences::Root)(Fl_Preferences::C_LOCALE|Fl_Preferences::CLEAR)); prefs.clear(); write(prefs, FLD_TOOL_STORE_FILE); return 0; @@ -721,7 +722,7 @@ void Layout_List::read(Fl_Preferences &prefs, fld::Tool_Store storage) { } } if (cs_ptr) { - current_suite(std::string(cs_ptr)); + current_suite(cs_ptr); ::free(cs_ptr); } current_preset(cp); @@ -758,7 +759,7 @@ void Layout_List::read(fld::io::Project_Reader *in) { const char *key; key = in->read_word(1); if (key && !strcmp(key, "{")) { - std::string cs; + const char *cs = 0; int cp = 0; for (;;) { key = in->read_word(); @@ -803,11 +804,12 @@ void Layout_List::current_suite(int ix) { \param[in] arg_name name of the selected suite \return if no name is given or the name is not found, keep the current suite selected */ -void Layout_List::current_suite(std::string arg_name) { - if (arg_name.empty()) return; - for (int i = 0; i < list_size_; ++i) { +void Layout_List::current_suite(const char *arg_name) { + if (!arg_name || !arg_name[0]) return; + int i; + for (i = 0; i < list_size_; ++i) { Layout_Suite &suite = list_[i]; - if (suite.name_ && (strcmp(suite.name_, arg_name.c_str()) == 0)) { + if (suite.name_ && (strcmp(suite.name_, arg_name) == 0)) { current_suite(i); break; } diff --git a/fluid/app/Snap_Action.h b/fluid/app/Snap_Action.h index 6bbe07bb8..7c1e3fabc 100644 --- a/fluid/app/Snap_Action.h +++ b/fluid/app/Snap_Action.h @@ -18,7 +18,6 @@ #define _FLUID_FD_SNAP_ACTION_H #include "../fld_tool_store.h" -#include <string> class Window_Node; class Widget_Node; @@ -131,7 +130,6 @@ public: bool list_is_static_; int current_suite_; int current_preset_; - std::string filename_; public: Layout_List(); ~Layout_List(); @@ -139,7 +137,7 @@ public: void update_menu_labels(); int current_suite() const { return current_suite_; } void current_suite(int ix); - void current_suite(std::string); + void current_suite(const char *); int current_preset() const { return current_preset_; } void current_preset(int ix); Layout_Suite &operator[](int ix) { return list_[ix]; } @@ -147,8 +145,8 @@ public: void rename(const char *name); void capacity(int); - int load(const std::string &filename); - int save(const std::string &filename); + int load(const char *filename); + int save(const char *filename); void write(Fl_Preferences &prefs, fld::Tool_Store storage); void read(Fl_Preferences &prefs, fld::Tool_Store storage); void write(fld::io::Project_Writer*); |
