From a0724ab7c4fedbd037d5b72332ae47fde8584dff Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sat, 4 Dec 2021 20:36:11 +0100 Subject: Add fl_message_icon_label() function (STR #2762) This message icon label (usually one character) will be used in the next call of one of the common dialogs. test/ask.cxx: use fl_message_icon_label() --- src/Fl_Message.cxx | 17 ++++++++++++++++- src/Fl_Message.h | 4 ++++ src/fl_ask.cxx | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Fl_Message.cxx b/src/Fl_Message.cxx index 1b93ecad3..0aa7ed587 100644 --- a/src/Fl_Message.cxx +++ b/src/Fl_Message.cxx @@ -65,6 +65,8 @@ const char *Fl_Message::message_title_default_; const char *Fl_Message::message_title_; +const char *Fl_Message::message_icon_label_; + Fl_Box *Fl_Message::message_icon_; char *Fl_Message::input_buffer_; @@ -123,6 +125,9 @@ void Fl_Message::window_cb_(Fl_Widget *w, void *d) { The constructor creates a default message window and sets the icon type to the given \p iconlabel which can be any character (or string). + If fl_message_icon_label() has been called before this label is used + instead and reset to NULL after the message window has been created. + Message text box (Fl_Box), icon (Fl_Box), and an input (Fl_Input) widgets are created and initialized. Three buttons are created and arranged right to left in the message window. The second (middle) button is an Fl_Return_Button. @@ -157,7 +162,13 @@ Fl_Message::Fl_Message(const char *iconlabel) icon_->labelsize(icon_template->labelsize()); icon_->color(icon_template->color()); icon_->labelcolor(icon_template->labelcolor()); - icon_->label(iconlabel); + + if (message_icon_label_) { // fl_message_icon_label() has been called + icon_->copy_label(message_icon_label_); + message_icon_label_ = 0; + } else { // use default (static, per message default string) + icon_->label(iconlabel); + } window_->end(); // don't add the buttons automatically @@ -526,6 +537,10 @@ void Fl_Message::message_title_default(const char *title) { message_title_default_ = strdup(title); } +void Fl_Message::icon_label(const char *str) { + message_icon_label_ = str; +} + /** \} \endcond diff --git a/src/Fl_Message.h b/src/Fl_Message.h index 83dfad1df..7e6cfd623 100644 --- a/src/Fl_Message.h +++ b/src/Fl_Message.h @@ -65,6 +65,9 @@ private: static const char *message_title_; static const char *message_title_default_; + // icon label for next dialog (STR #2762) + static const char *message_icon_label_; + // Note: since Fl_Message objects are destroyed before fl_input() // and fl_password() return their input text, we *need* to store // the text in an internal (static) buffer. :-( @@ -89,6 +92,7 @@ public: static Fl_Box *message_icon(); static void message_title(const char *title); static void message_title_default(const char *title); + static void icon_label(const char *str); /** Implements fl_message_position(const int, const int y, const int center). */ static void message_position(const int x, const int y, const int center) { diff --git a/src/fl_ask.cxx b/src/fl_ask.cxx index a4e44ffc3..95031753e 100644 --- a/src/fl_ask.cxx +++ b/src/fl_ask.cxx @@ -560,4 +560,28 @@ void fl_message_title_default(const char *title) { Fl_Message::message_title_default(title); } +/** Sets the icon label of the dialog window used in many common dialogs. + + This icon label will be used in the next call of one of the + common dialogs like fl_message(), fl_alert(), fl_ask(), fl_choice(), + fl_input(), fl_password(). + + The label \p str is stored internally as a reference, it must be + in scope until the dialog function (e.g. fl_choice) is called. + + It applies only to the \b next call of one of the common dialogs and + will be reset after that call so the next dialog will use its default + label unless set again. + + \note This label string must be short, usually only one character so + it fits in the icon box. You can use any valid UTF-8 character, e.g. + the Euro sign ("€") which is three bytes in UTF-8 encoding. + + \code #include \endcode + \param[in] str icon label +*/ +void fl_message_icon_label(const char *str) { + Fl_Message::icon_label(str); +} + /** @} */ -- cgit v1.2.3