summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2021-12-04 20:36:11 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2021-12-04 20:36:11 +0100
commita0724ab7c4fedbd037d5b72332ae47fde8584dff (patch)
tree2c2c37ac226d7b26d2c050fc62af12aa0f9efe68
parent130f864d1d3f02f854a5f4085a49318a03a8eea0 (diff)
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()
-rw-r--r--FL/fl_ask.H2
-rw-r--r--src/Fl_Message.cxx17
-rw-r--r--src/Fl_Message.h4
-rw-r--r--src/fl_ask.cxx24
-rw-r--r--test/ask.cxx7
5 files changed, 51 insertions, 3 deletions
diff --git a/FL/fl_ask.H b/FL/fl_ask.H
index b96c94d30..7df49a8fe 100644
--- a/FL/fl_ask.H
+++ b/FL/fl_ask.H
@@ -95,6 +95,8 @@ inline void fl_message_position(Fl_Widget &widget) {
FL_EXPORT void fl_message_title(const char *title);
FL_EXPORT void fl_message_title_default(const char *title);
+FL_EXPORT void fl_message_icon_label(const char *str);
+
// pointers you can use to change FLTK to another language:
extern FL_EXPORT const char *fl_no;
extern FL_EXPORT const char *fl_yes;
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 <FL/fl_ask.H> \endcode
+ \param[in] str icon label
+*/
+void fl_message_icon_label(const char *str) {
+ Fl_Message::icon_label(str);
+}
+
/** @} */
diff --git a/test/ask.cxx b/test/ask.cxx
index 0800f2d01..8c708cad1 100644
--- a/test/ask.cxx
+++ b/test/ask.cxx
@@ -35,10 +35,13 @@
void rename_button(Fl_Widget *o, void *v) {
int what = fl_int(v);
Fl_String input;
- if (what == 0)
+ if (what == 0) {
+ fl_message_icon_label("§");
input = fl_input_str(0, "Input (no size limit, use ctrl/j for newline):", o->label());
- else
+ } else {
+ fl_message_icon_label("€");
input = fl_password_str(20, "Enter password (max. 20 characters):", o->label());
+ }
if (input.value()) {
o->copy_label(input.value());
o->redraw();