diff --git a/dw/fltkui.cc b/dw/fltkui.cc index 0989467..fb4f839 100644 --- a/dw/fltkui.cc +++ b/dw/fltkui.cc @@ -18,6 +18,9 @@ */ +#include +#include +#include #include "fltkcore.hh" #include "fltkflatview.hh" @@ -56,8 +59,7 @@ static Fl_Color fltkui_dimmed(Fl_Color c, Fl_Color bg) class CustInput2 : public Fl_Input { public: CustInput2 (int x, int y, int w, int h, const char* l=0); - ~CustInput2 () { if (placeholder) free(placeholder); }; - void set_placeholder(const char *str); + void set_placeholder(std::string_view str); int show_placeholder(); int show_normal(const char *str); void textcolor(Fl_Color c); @@ -66,7 +68,7 @@ public: const char* value(); int handle(int e); private: - char *placeholder; + std::optional< std::string > placeholder; bool showing_placeholder; Fl_Color usual_color; int usual_type; @@ -75,7 +77,6 @@ private: CustInput2::CustInput2 (int x, int y, int w, int h, const char* l) : Fl_Input(x,y,w,h,l) { - placeholder = NULL; showing_placeholder = false; usual_color = FL_BLACK; /* just init until widget style is set */ } @@ -101,7 +102,7 @@ int CustInput2::show_placeholder() showing_placeholder = true; Fl_Input::textcolor(fltkui_dimmed(usual_color, color())); Fl_Input::input_type(FL_NORMAL_INPUT); - ret = Fl_Input::value(placeholder); + ret = Fl_Input::value(placeholder.value().c_str()); position(0); return ret; } @@ -109,11 +110,9 @@ int CustInput2::show_placeholder() /* * Set the placeholder text. */ -void CustInput2::set_placeholder(const char *str) +void CustInput2::set_placeholder(const std::string_view str) { - if (placeholder) - free(placeholder); - placeholder = dStrdup(str); + placeholder = str; if ((Fl::focus() != this) && !*value()) { show_placeholder();