diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-10-22 19:30:37 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-10-22 19:35:17 +0200 |
| commit | 1209e9dcd7e1e97bedc747d06ba4eea837562158 (patch) | |
| tree | 7897d3c61368958f191bfe684b96d1d08467a2bb /src/fl_ask.cxx | |
| parent | 05ac0247cbd902f910fa89f8d4f4fde9de904b0f (diff) | |
Make Fl_String and Fl_Int_Vector private (#789)
- add CMake option 'OPTION_USE_STD'
- add configure option '--enable-use_std'
- move FL/Fl_String.H to src/Fl_String.H
- move FL/Fl_Int_Vector.H to src/Fl_Int_Vector.H
- remove Fl_String from demo program examples/callbacks.cxx
- remove Fl_Int_Vector from public header FL/Fl_Table.H
- some methods of Fl_Table are no longer inline
- add CMake option OPTION_USE_STD to allow std::string in some
selected functions and methods
Experimental, may be removed before release:
- use either Fl_Int_Vector or std::vector in Fl_Table depending
on CMake OPTION_USE_STD or configure --enable-use_std
Move all fl_filename* functions that use Fl_String to fluid
Main changes in fluid:
- add fluid_filename.h and .cxx
- include "fluid_filename.h" rather than <FL/filename.H>
Update fl_input(), fl_password() and test/ask
- add maxchar parameter to fl_input() and fl_password()
- fl_input_str() and fl_password_str() are optional and return
std::string if enabled (FLTK_USE_STD)
Diffstat (limited to 'src/fl_ask.cxx')
| -rw-r--r-- | src/fl_ask.cxx | 108 |
1 files changed, 84 insertions, 24 deletions
diff --git a/src/fl_ask.cxx b/src/fl_ask.cxx index 6ed6b2667..29221d494 100644 --- a/src/fl_ask.cxx +++ b/src/fl_ask.cxx @@ -292,14 +292,10 @@ Fl_Widget *fl_message_icon() { /** Shows an input dialog displaying the \p fmt message with variable arguments. - This version of fl_input() is deprecated. The return value points - to an internal allocated string that may be changed later. You must - copy the string immediately after return from this method - at least + Returns the string in an internally allocated buffer that may be changed later. + You \b must copy the string immediately after return from this method - at least before the next execution of the event loop. - \deprecated Please use - fl_input_str(int maxchar, const char *fmt, const char *defstr, ...) instead. - \code #include <FL/fl_ask.H> \endcode \param[in] fmt can be used as an sprintf-like format and variables for the message text @@ -313,11 +309,45 @@ const char *fl_input(const char *fmt, const char *defstr, ...) { Fl_Message msg("?"); va_list ap; va_start(ap, defstr); - const char *r = msg.input_innards(fmt, ap, defstr, FL_NORMAL_INPUT, -1); + const char *r = msg.input_innards(fmt, ap, defstr, FL_NORMAL_INPUT, 0, false); + va_end(ap); + return r; +} + + +/** Shows an input dialog displaying the \p fmt message with variable arguments. + + This is the same as const char *fl_input(const char *fmt, const char *defstr, ...) + except that it has an additional parameter to limit the number of characters + the user can input. + + Returns the string in an internally allocated buffer that may be changed later. + You \b must copy the string immediately after return from this method - at least + before the next execution of the event loop. + + \code #include <FL/fl_ask.H> \endcode + + \param[in] fmt can be used as an sprintf-like format and variables for the message text + \param[in] defstr defines the default returned string if no text is entered + + \return the user string input if OK was pushed + \retval NULL if Cancel was pushed or the window was closed by the user +*/ +const char *fl_input(int maxchar, const char *fmt, const char *defstr, ...) { + + Fl_Message msg("?"); + if (maxchar < 0) maxchar = 0; + va_list ap; + va_start(ap, defstr); + const char *r = msg.input_innards(fmt, ap, defstr, FL_NORMAL_INPUT, maxchar, false); va_end(ap); return r; } + + +#if (FLTK_USE_STD) + /** Shows an input dialog displaying the \p fmt message with variable arguments. Like fl_input(), but this method has the additional argument \p maxchar @@ -326,7 +356,7 @@ const char *fl_input(const char *fmt, const char *defstr, ...) { in the string is larger than \p maxchar. Other than the deprecated fl_input() method w/o the \p maxchar argument, this one - returns the string in an Fl_String object that must be released after use. This + returns the string in an std::string object that must be released after use. This can be a local/automatic variable. The \p ret variable is set to 0 if the user clicked OK, and to a negative @@ -338,7 +368,7 @@ const char *fl_input(const char *fmt, const char *defstr, ...) { Example: \code { int ret; - Fl_String str = fl_input_str(ret, 0, "Enter text:", ""); + std::string str = fl_input_str(ret, 0, "Enter text:", ""); if (ret < 0) printf("Text input was canceled.\n"); else @@ -356,31 +386,33 @@ const char *fl_input(const char *fmt, const char *defstr, ...) { \since 1.4.0 */ -Fl_String fl_input_str(int &ret, int maxchar, const char *fmt, const char *defstr, ...) { +std::string fl_input_str(int &ret, int maxchar, const char *fmt, const char *defstr, ...) { Fl_Message msg("?"); if (maxchar < 0) maxchar = 0; va_list ap; va_start(ap, defstr); - const char *r = msg.input_innards(fmt, ap, defstr, FL_NORMAL_INPUT, maxchar); + const char *r = msg.input_innards(fmt, ap, defstr, FL_NORMAL_INPUT, maxchar, true); va_end(ap); ret = (r == NULL) ? -1 : 0; - return Fl_String(r); + return (r == NULL) ? std::string("") : std::string(r); } /** Shows an input dialog displaying the \p fmt message with variable arguments. \note No information is given if the user canceled the dialog or clicked OK. \see fl_input_str(int &ret, int maxchar, const char *label, const char *deflt = 0, ...) */ -Fl_String fl_input_str(int maxchar, const char *fmt, const char *defstr, ...) { +std::string fl_input_str(int maxchar, const char *fmt, const char *defstr, ...) { Fl_Message msg("?"); if (maxchar < 0) maxchar = 0; va_list ap; va_start(ap, defstr); - const char *r = msg.input_innards(fmt, ap, defstr, FL_NORMAL_INPUT, maxchar); + const char *r = msg.input_innards(fmt, ap, defstr, FL_NORMAL_INPUT, maxchar, true); va_end(ap); - return Fl_String(r); + return (r == NULL) ? std::string("") : std::string(r); } +#endif // FLTK_USE_STD + /** Shows an input dialog displaying the \p fmt message with variable arguments. Like fl_input() except the input text is not shown, @@ -401,18 +433,44 @@ const char *fl_password(const char *fmt, const char *defstr, ...) { Fl_Message msg("?"); va_list ap; va_start(ap, defstr); - const char *r = msg.input_innards(fmt, ap, defstr, FL_SECRET_INPUT); + const char *r = msg.input_innards(fmt, ap, defstr, FL_SECRET_INPUT, 0, false); + va_end(ap); + return r; +} + +/** Shows an input dialog displaying the \p fmt message with variable arguments. + + Like fl_input() except the input text is not shown, + '*' or similar replacement characters are displayed instead. + + \code #include <FL/fl_ask.H> \endcode + + \param[in] maxchar input lenght limit in chars, 0 = no limit + \param[in] fmt can be used as an sprintf-like format and variables for the message text + \param[in] defstr defines the default returned string if no text is entered + + \return the user string input if OK was pushed + \retval NULL if Cancel was pushed or the window was closed by the user +*/ +const char *fl_password(int maxchar, const char *fmt, const char *defstr, ...) { + Fl_Message msg("?"); + if (maxchar < 0) maxchar = 0; + va_list ap; + va_start(ap, defstr); + const char *r = msg.input_innards(fmt, ap, defstr, FL_SECRET_INPUT, maxchar, false); va_end(ap); return r; } +#if (FLTK_USE_STD) + /** Shows an input dialog displaying the \p fmt message with variable arguments. Like fl_input_str() except the input text is not shown, '*' or similar replacement characters are displayed instead. - Other than the deprecated fl_password() method w/o the \p maxchar argument, this - one returns the string in an Fl_String object that must be released after use. + Other than the fl_password() method w/o the \p maxchar argument, this one + returns the string in an std::string object that must be released after use. This can be a local/automatic variable. For an example see fl_input_str() @@ -429,31 +487,33 @@ const char *fl_password(const char *fmt, const char *defstr, ...) { \since 1.4.0 */ -Fl_String fl_password_str(int &ret, int maxchar, const char *fmt, const char *defstr, ...) { +std::string fl_password_str(int &ret, int maxchar, const char *fmt, const char *defstr, ...) { Fl_Message msg("?"); if (maxchar < 0) maxchar = 0; va_list ap; va_start(ap, defstr); - const char *r = msg.input_innards(fmt, ap, defstr, FL_SECRET_INPUT, maxchar); + const char *r = msg.input_innards(fmt, ap, defstr, FL_SECRET_INPUT, maxchar, true); va_end(ap); ret = (r == NULL) ? -1 : 0; - return Fl_String(r); + return (r == NULL) ? std::string("") : std::string(r); } /** Shows an input dialog displaying the \p fmt message with variable arguments. \note No information is given if the user canceled the dialog or clicked OK. \see fl_password_str(int &ret, int maxchar, const char *label, const char *deflt = 0, ...) */ -Fl_String fl_password_str(int maxchar, const char *fmt, const char *defstr, ...) { +std::string fl_password_str(int maxchar, const char *fmt, const char *defstr, ...) { Fl_Message msg("?"); if (maxchar < 0) maxchar = 0; va_list ap; va_start(ap, defstr); - const char *r = msg.input_innards(fmt, ap, defstr, FL_SECRET_INPUT, maxchar); + const char *r = msg.input_innards(fmt, ap, defstr, FL_SECRET_INPUT, maxchar, true); va_end(ap); - return Fl_String(r); + return (r == NULL) ? std::string("") : std::string(r); } +#endif // FLTK_USE_STD + /** Sets the preferred position for the message box used in many common dialogs like fl_message(), fl_alert(), |
