Re-enable nested (aka recursive) common dialogs (STR 3242, #282)

Apply Fl_Dialog_r10831.patch as given in STR 3242:
https://www.fltk.org/strfiles/3242/Fl_Dialog_r10831.patch

Reformat, add missing pieces, rename private members, cleanup...

Improve documentation, add fl_choice_n() (issue #282)

New methods fl_input_str() and fl_password_str() return Fl_String
This commit is contained in:
Albrecht Schlosser 2021-12-04 13:35:47 +01:00
parent 2404656266
commit b6de09cff2
11 changed files with 1275 additions and 582 deletions

View File

@ -1,7 +1,7 @@
//
// Standard dialog header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2020 by Bill Spitzak and others.
// Copyright 1998-2021 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -18,44 +18,71 @@
API for common dialogs.
*/
#ifndef fl_ask_H
# define fl_ask_H
#ifndef _FL_fl_ask_H_
#define _FL_fl_ask_H_
#include <FL/Enumerations.H>
#include <FL/Fl_String.H>
#include <FL/fl_attr.h>
# include "Enumerations.H"
# include "fl_attr.h"
class Fl_Widget;
/** Different system beeps available.
\sa fl_beep(int) */
enum Fl_Beep {
FL_BEEP_DEFAULT = 0, ///< Default beep.
FL_BEEP_MESSAGE, ///< Message beep.
FL_BEEP_ERROR, ///< Error beep.
FL_BEEP_QUESTION, ///< Question beep.
FL_BEEP_PASSWORD, ///< Password beep.
FL_BEEP_NOTIFICATION ///< Notification beep.
FL_BEEP_DEFAULT = 0, ///< Default beep.
FL_BEEP_MESSAGE, ///< Message beep.
FL_BEEP_ERROR, ///< Error beep.
FL_BEEP_QUESTION, ///< Question beep.
FL_BEEP_PASSWORD, ///< Password beep.
FL_BEEP_NOTIFICATION ///< Notification beep.
};
FL_EXPORT void fl_beep(int type = FL_BEEP_DEFAULT);
FL_EXPORT void fl_message(const char *,...) __fl_attr((__format__ (__printf__, 1, 2)));
FL_EXPORT void fl_alert(const char *,...) __fl_attr((__format__ (__printf__, 1, 2)));
FL_EXPORT void fl_message(const char *, ...) __fl_attr((__format__(__printf__, 1, 2)));
FL_EXPORT void fl_alert(const char *, ...) __fl_attr((__format__(__printf__, 1, 2)));
// fl_ask() is deprecated since it uses "Yes" and "No" for the buttons,
// which does not conform to the current FLTK Human Interface Guidelines.
// Use fl_choice() instead with the appropriate verbs instead.
FL_EXPORT int fl_ask(const char *,...) __fl_attr((__format__ (__printf__, 1, 2), __deprecated__));
FL_EXPORT int fl_choice(const char *q,const char *b0,const char *b1,const char *b2,...) __fl_attr((__format__ (__printf__, 1, 5)));
FL_EXPORT const char *fl_input(const char *label, const char *deflt = 0, ...) __fl_attr((__format__ (__printf__, 1, 3)));
FL_EXPORT const char *fl_password(const char *label, const char *deflt = 0, ...) __fl_attr((__format__ (__printf__, 1, 3)));
// Use fl_choice() or fl_choice_n() with the appropriate verbs instead.
FL_EXPORT int fl_ask(const char *, ...) __fl_attr((__format__(__printf__, 1, 2), __deprecated__));
FL_EXPORT int fl_choice(const char *q, const char *b0, const char *b1, const char *b2, ...)
__fl_attr((__format__(__printf__, 1, 5)));
FL_EXPORT const char *fl_input(const char *label, const char *deflt = 0, ...) __fl_attr((__format__(__printf__, 1, 3)));
FL_EXPORT const char *fl_password(const char *label, const char *deflt = 0, ...)
__fl_attr((__format__(__printf__, 1, 3)));
// since FLTK 1.3.8:
// - fl_choice_n() with extended return value (-2, -1, 0, 1, 2)
FL_EXPORT int fl_choice_n(const char *q, const char *b0, const char *b1, const char *b2, ...)
__fl_attr((__format__(__printf__, 1, 5)));
// since FLTK 1.4.0:
// - fl_input_str() with limited input size
// - fl_password_str() with limited input size (*_str)
FL_EXPORT Fl_String fl_input_str(int maxchar, const char *label, const char *deflt = 0, ...)
__fl_attr((__format__(__printf__, 2, 4)));
FL_EXPORT Fl_String fl_password_str(int maxchar, const char *label, const char *deflt = 0, ...)
__fl_attr((__format__(__printf__, 2, 4)));
FL_EXPORT Fl_Widget *fl_message_icon();
extern FL_EXPORT Fl_Font fl_message_font_;
extern FL_EXPORT Fl_Fontsize fl_message_size_;
inline void fl_message_font(Fl_Font f, Fl_Fontsize s) {
fl_message_font_ = f; fl_message_size_ = s;}
fl_message_font_ = f;
fl_message_size_ = s;
}
FL_EXPORT void fl_message_hotspot(int enable);
FL_EXPORT int fl_message_hotspot(void);
// since FLTK 1.4.0: fl_message_position()
FL_EXPORT void fl_message_position(const int x, const int y, const int center = 0);
FL_EXPORT void fl_message_position(Fl_Widget *widget);
FL_EXPORT int fl_message_position(int *x = 0, int *y = 0);
@ -69,9 +96,10 @@ FL_EXPORT void fl_message_title(const char *title);
FL_EXPORT void fl_message_title_default(const char *title);
// pointers you can use to change FLTK to another language:
extern FL_EXPORT const char* fl_no;
extern FL_EXPORT const char* fl_yes;
extern FL_EXPORT const char* fl_ok;
extern FL_EXPORT const char* fl_cancel;
extern FL_EXPORT const char* fl_close;
#endif // !fl_ask_H
extern FL_EXPORT const char *fl_no;
extern FL_EXPORT const char *fl_yes;
extern FL_EXPORT const char *fl_ok;
extern FL_EXPORT const char *fl_cancel;
extern FL_EXPORT const char *fl_close;
#endif // !_FL_fl_ask_H_

View File

@ -55,6 +55,7 @@ alignment_panel.o: ../FL/Fl_Scrollbar.H
alignment_panel.o: ../FL/Fl_Simple_Terminal.H
alignment_panel.o: ../FL/Fl_Slider.H
alignment_panel.o: ../FL/Fl_Spinner.H
alignment_panel.o: ../FL/Fl_String.H
alignment_panel.o: ../FL/Fl_Tabs.H
alignment_panel.o: ../FL/Fl_Text_Buffer.H
alignment_panel.o: ../FL/Fl_Text_Display.H
@ -201,7 +202,7 @@ ExternalCodeEditor_UNIX.o: ../FL/fl_ask.H
ExternalCodeEditor_UNIX.o: ../FL/fl_attr.h
ExternalCodeEditor_UNIX.o: ../FL/fl_casts.H
ExternalCodeEditor_UNIX.o: ../FL/Fl_Export.H
ExternalCodeEditor_UNIX.o: ../FL/fl_string.h
ExternalCodeEditor_UNIX.o: ../FL/Fl_String.H
ExternalCodeEditor_UNIX.o: ../FL/fl_types.h
ExternalCodeEditor_UNIX.o: ../FL/fl_utf8.h
ExternalCodeEditor_UNIX.o: ../FL/platform_types.h
@ -407,7 +408,7 @@ fluid.o: ../FL/Fl_Shared_Image.H
fluid.o: ../FL/Fl_Simple_Terminal.H
fluid.o: ../FL/Fl_Slider.H
fluid.o: ../FL/Fl_Spinner.H
fluid.o: ../FL/fl_string.h
fluid.o: ../FL/Fl_String.H
fluid.o: ../FL/Fl_Tabs.H
fluid.o: ../FL/Fl_Text_Buffer.H
fluid.o: ../FL/Fl_Text_Display.H
@ -543,7 +544,7 @@ Fl_Function_Type.o: ../FL/fl_show_input.H
Fl_Function_Type.o: ../FL/Fl_Simple_Terminal.H
Fl_Function_Type.o: ../FL/Fl_Slider.H
Fl_Function_Type.o: ../FL/Fl_Spinner.H
Fl_Function_Type.o: ../FL/fl_string.h
Fl_Function_Type.o: ../FL/Fl_String.H
Fl_Function_Type.o: ../FL/Fl_Tabs.H
Fl_Function_Type.o: ../FL/Fl_Text_Buffer.H
Fl_Function_Type.o: ../FL/Fl_Text_Display.H

View File

@ -56,6 +56,7 @@ set (CPPFILES
Fl_Menu_Window.cxx
Fl_Menu_add.cxx
Fl_Menu_global.cxx
Fl_Message.cxx
Fl_Multi_Label.cxx
Fl_Native_File_Chooser.cxx
Fl_Overlay_Window.cxx

View File

@ -21,8 +21,11 @@
// *** BEGIN OUT OF SOURCE DOCUMENTATION ***
/** \defgroup group_comdlg Common Dialogs classes and functions
@{
/** \defgroup group_comdlg Common Dialog Classes and Functions
\brief Common dialog functions for file selection, message output, and more.
@{
*/
/** \class Fl_File_Chooser
The Fl_File_Chooser widget displays a standard file selection

532
src/Fl_Message.cxx Normal file
View File

@ -0,0 +1,532 @@
//
// Common dialog implementation for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2021 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//
/**
\cond DriverDev
\addtogroup DriverDeveloper
\{
*/
/**
\file Fl_Message.cxx - Base class for common dialogs.
This is the base class for all common FLTK dialog windows used in
fl_message(), fl_ask(), fl_choice(), fl_input(), and fl_password().
\note <b>Internal use only. This class may be changed as required
without notice.</b>\n
This class is reserved for FLTK's internal usage in common dialogs
in FLTK 1.4.x and later. The header file is "hidden" in the src/
folder and not installed with the public header files.
\since 1.4.0
All common dialogs can be altered by changing the contents of some
static class variables. This is done by accessor methods like
fl_message_title() and others defined in FL/fl_ask.H. This is for
backwards compatibility with FLTK 1.3.x and earlier.
\note The documentation is only visible if the CMake option
\c 'OPTION_INCLUDE_DRIVER_DOCUMENTATION' is enabled.
*/
#include <FL/Fl.H>
#include "flstring.h"
#include <FL/fl_ask.H>
#include "Fl_Message.h" // intentionally "hidden" in src/...
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Return_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Secret_Input.H>
#include <FL/fl_draw.H>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
// Fl_Message static variables
const char *Fl_Message::message_title_default_;
const char *Fl_Message::message_title_;
Fl_Box *Fl_Message::message_icon_;
char *Fl_Message::input_buffer_;
int Fl_Message::input_size_;
int Fl_Message::enable_hotspot_ = 1;
int Fl_Message::form_x_ = 0;
int Fl_Message::form_y_ = 0;
int Fl_Message::form_position_ = 0; // 0 = not set, 1 = absolute, 2 = centered
/**
Fl_Message's internal button callback.
This callback function is used when the user pushes a button, presses the
\c Return key, or uses a valid shortcut for one of the buttons.
The internal return value \p retval_ is set according to the button that
was invoked (0, 1, 2) and \p window_closed_ is set to 0 (dialog closed
by dialog button). Then the dialog window is closed (hidden).
*/
void Fl_Message::button_cb_(Fl_Widget *w, void *d) {
Fl_Window *window = w->window();
Fl_Message *dialog = (Fl_Message *)window->user_data();
dialog->window_closed_ = 0;
dialog->retval_ = fl_int(d); // button
window->hide();
} // button_cb_()
/**
Fl_Message's internal window callback.
This callback function is used internally when the dialog window is closed
by the user with the window close button or by pressing \c Escape.
The internal return value \p retval_ is set to 0 (i.e. button 0) and
\p window_closed_ is set to -1 (Escape) or -2 (window close button).
Then the dialog window is closed (hidden).
*/
void Fl_Message::window_cb_(Fl_Widget *w, void *d) {
Fl_Window *window = (Fl_Window *)w;
Fl_Message *dialog = (Fl_Message *)window->user_data();
if ((Fl::event() == FL_KEYBOARD || Fl::event() == FL_SHORTCUT) &&
(Fl::event_key() == FL_Escape))
dialog->window_closed_ = -1;
else
dialog->window_closed_ = -2;
dialog->retval_ = 0; // either window or button 0
window->hide();
} // window_cb_()
/**
Fl_Message constructor.
The constructor creates a default message window and sets the icon type
to the given \p iconlabel which can be any character (or string).
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.
The message window is set to modal()
*/
Fl_Message::Fl_Message(const char *iconlabel)
: window_(0)
, retval_(0)
, window_closed_(0) {
// Make sure that the dialog does not become the child of some current group.
Fl_Group *previous_group = Fl_Group::current();
if (previous_group)
Fl_Group::current(0);
// create widgets
window_ = new Fl_Window(400, 150, NULL);
message_ = new Fl_Box(60, 25, 340, 20);
message_->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
input_ = new Fl_Input(60, 37, 340, 23);
input_->hide();
Fl_Box *icon_template = message_icon(); // use template for icon box
icon_ = new Fl_Box(10, 10, 50, 50);
icon_->box(icon_template->box());
icon_->labelfont(icon_template->labelfont());
icon_->labelsize(icon_template->labelsize());
icon_->color(icon_template->color());
icon_->labelcolor(icon_template->labelcolor());
icon_->label(iconlabel);
window_->end(); // don't add the buttons automatically
// create the buttons (positions: right to left)
// button 1 is a return button
for (int b = 0, x = 310; b < 3; b++, x -= 100) {
if (b == 1) {
button_[b] = new Fl_Return_Button(x, 70, 90, 23);
} else {
button_[b] = new Fl_Button(x, 70, 90, 23);
}
button_[b]->align(FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
button_[b]->callback(button_cb_, fl_voidptr(b));
}
// add the buttons left to right for tab navigation
for (int b = 2; b >= 0; b--) {
window_->add(button_[b]);
}
window_->begin();
window_->resizable(new Fl_Box(60, 10, 110 - 60, 27));
window_->end();
window_->callback(window_cb_, this);
window_->set_modal();
// restore previous group
Fl_Group::current(previous_group);
}
/**
Resizes the form and widgets so that they hold everything
that is asked of them.
*/
void Fl_Message::resizeform() {
int i;
int message_w, message_h;
int text_height;
int button_w[3], button_h[3];
int x, w, h, max_w, max_h;
const int icon_size = 50;
fl_font(message_->labelfont(), message_->labelsize());
message_w = message_h = 0;
fl_measure(message_->label(), message_w, message_h);
message_w += 10;
message_h += 10;
if (message_w < 340)
message_w = 340;
if (message_h < 30)
message_h = 30;
fl_font(button_[0]->labelfont(), button_[0]->labelsize());
memset(button_w, 0, sizeof(button_w));
memset(button_h, 0, sizeof(button_h));
for (max_h = 25, i = 0; i < 3; i++)
if (button_[i]->visible()) {
fl_measure(button_[i]->label(), button_w[i], button_h[i]);
if (i == 1)
button_w[1] += 20; // account for return button arrow
button_w[i] += 30;
button_h[i] += 10;
if (button_h[i] > max_h)
max_h = button_h[i];
}
if (input_->visible())
text_height = message_h + 25;
else
text_height = message_h;
max_w = message_w + 10 + icon_size;
w = button_w[0] + button_w[1] + button_w[2] - 10;
if (w > max_w)
max_w = w;
message_w = max_w - 10 - icon_size;
w = max_w + 20;
h = max_h + 30 + text_height;
window_->size(w, h);
window_->size_range(w, h, w, h);
message_->resize(20 + icon_size, 10, message_w, message_h);
icon_->resize(10, 10, icon_size, icon_size);
icon_->labelsize(icon_size - 10);
input_->resize(20 + icon_size, 10 + message_h, message_w, 25);
for (x = w, i = 0; i < 3; i++) {
if (button_w[i]) {
x -= button_w[i];
button_[i]->resize(x, h - 10 - max_h, button_w[i] - 10, max_h);
}
}
}
/**
Does all Fl_Message window internals for messages with and w/o an input field.
This method finalizes the layout of the message window, arranges (shows or hides)
the buttons and the optional text input widget, sets the message window title,
pops up the window, and waits for user input.
The message window is positioned according to the positioning options set before
calling the message function.
The private variables \p retval_ and \p window_closed_ are set depending
on the user action (pushing a button or closing the window).
\note The above mentioned variables must be evaluated before the event
loop is called because they might be overwritten by another dialog.
It is safe to evaluate the variables before the message function returns.
\param[in] fmt printf style format used in the user function call
\param[in] ap argument list provided by the user function call
\param[in] b0 text of button 0 (right: usually the "cancel" button)
\param[in] b1 text of button 1 (middle)
\param[in] b2 text of button 2 (left)
\returns return code
\retval 0 for Escape, window close, or button 0
\retval 1 button 1 was pushed
\retval 2 button 2 was pushed
*/
int Fl_Message::innards(const char *fmt, va_list ap, const char *b0, const char *b1, const char *b2) {
Fl::pushed(0); // stop dragging (STR #2159)
char buffer[1024];
if (!strcmp(fmt, "%s")) {
message_->label(va_arg(ap, const char *));
} else {
::vsnprintf(buffer, sizeof(buffer) - 1, fmt, ap);
message_->label(buffer);
}
message_->labelfont(fl_message_font_);
if (fl_message_size_ == -1)
message_->labelsize(FL_NORMAL_SIZE);
else
message_->labelsize(fl_message_size_);
if (b0) {
button_[0]->show();
button_[0]->label(b0);
button_[1]->position(210, 70);
} else {
button_[0]->hide();
button_[1]->position(310, 70);
}
if (b1) {
button_[1]->show();
button_[1]->label(b1);
} else
button_[1]->hide();
if (b2) {
button_[2]->show();
button_[2]->label(b2);
} else
button_[2]->hide();
resizeform();
if (button_[1]->visible() && !input_->visible())
button_[1]->take_focus();
if (form_position_) {
if (form_position_ == 2) { // centered
form_x_ -= window_->w() / 2;
form_y_ -= window_->h() / 2;
}
window_->position(form_x_, form_y_);
form_x_ = form_y_ = form_position_ = 0;
} else if (enable_hotspot_)
window_->hotspot(button_[0]);
else
window_->free_position();
if (b0 && Fl_Widget::label_shortcut(b0))
button_[0]->shortcut(0);
// set the one-time window title, if defined and a specific title is not set
if (!window_->label() && message_title_) {
window_->copy_label(message_title_);
message_title(0); // reset global message title (compat.)
}
// set default window title, if defined and a specific title is not set
if (!window_->label() && message_title_default_)
window_->copy_label(message_title_default_);
// deactivate Fl::grab() because it is incompatible with modal windows
Fl_Window *g = Fl::grab();
if (g)
Fl::grab(0);
Fl_Group *current_group = Fl_Group::current(); // make sure the dialog does not interfere with any active group
window_->show();
Fl_Group::current(current_group);
while (window_->shown())
Fl::wait();
if (g) // regrab the previous popup menu, if there was one
Fl::grab(g);
return retval_;
}
/**
Gets the default icon container (Fl_Box) used in common dialogs.
Many common dialogs like fl_message(), fl_alert(), fl_ask(),
fl_choice(), fl_input(), and fl_password() display an icon.
You can use this method to get the icon box (Fl_Box) and modify
the icon's box type, font, fontsize etc.
\since FLTK 1.4.0
\note This method replaces the deprecated method fl_message_icon().
Note that this new method correctly returns an Fl_Box * pointer,
whereas fl_message_icon() returns Fl_Widget *.
The current icon default values are:
- width and height: 50 (currently not changeable)
- box(FL_THIN_UP_BOX)
- labelfont(FL_TIMES_BOLD)
- labelsize(34)
- color(FL_WHITE)
- labelcolor(FL_BLUE)
These values may be changed in a future FLTK version (although this
is not very likely to happen).
If you change this then the changed values are used for subsequently
started common dialogs. This is intended to change the icon layout
for your application at startup time. It is not recommended to change
the default values for each message.
*/
Fl_Box *Fl_Message::message_icon() {
if (!Fl_Message::message_icon_) { // not yet initialized
Fl_Group *current_group = Fl_Group::current();
Fl_Group::current(0);
Fl_Box *o = Fl_Message::message_icon_ = new Fl_Box(10, 10, 50, 50);
o->box(FL_THIN_UP_BOX);
o->labelfont(FL_TIMES_BOLD);
o->labelsize(34);
o->color(FL_WHITE);
o->labelcolor(FL_BLUE);
Fl_Group::current(current_group);
}
return Fl_Message::message_icon_;
}
/**
Does all Fl_Message window internals for messages with a text input field.
\see innards()
*/
const char *Fl_Message::input_innards(const char *fmt, va_list ap, const char *defstr, uchar type, int maxchar) {
message_->position(60, 10);
input_->type(type);
input_->show();
input_->value(defstr);
input_->take_focus();
if (maxchar > 0)
input_->maximum_size(maxchar);
int r = innards(fmt, ap, fl_cancel, fl_ok, 0);
if (!r)
return 0;
if (input_->value()) {
int size = input_->size() + 1;
if (maxchar < 0) { // need to store the value in pre-allocated buffer
// The allocated input buffer starts with size 0 and is allocated
// in multiples of 128 bytes >= size. If both the size and the pointer
// are 0 (NULL) then realloc() allocates a /new/ buffer.
if (size > input_size_) {
size += 127;
size &= ~127;
input_buffer_ = (char *)realloc(input_buffer_, size);
input_size_ = size;
}
// Store the input. Note that value() can contain null bytes,
// so we use memcpy and add a terminating null byte as well.
memcpy(input_buffer_, input_->value(), input_->size());
input_buffer_[input_->size()] = '\0';
return (input_buffer_);
} else { // new version: allocate string buffer
char *buf = (char *)malloc(size);
memcpy(buf, input_->value(), input_->size());
buf[input_->size()] = '\0';
return (buf);
}
} else
return 0;
}
/** Sets the title of the dialog window used in many common dialogs.
This window \p title 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 \p title string is copied internally, so that you can use a
local variable or free the string immediately after this call. It
applies only to the \b next call of one of the common dialogs and
will be reset to an empty title (the default for all dialogs) after
that call.
\param[in] title window label, string copied internally
*/
void Fl_Message::message_title(const char *title) {
if (message_title_) {
free((void *)message_title_);
message_title_ = 0;
}
if (title)
message_title_ = strdup(title);
}
/** Sets the default title of the dialog window used in many common dialogs.
This window \p title will be used in all subsequent calls of one of the
common dialogs like fl_message(), fl_alert(), fl_ask(), fl_choice(),
fl_input(), fl_password(), unless a specific title has been set
with fl_message_title(const char *title).
The default is no title. You can override the default title for a
single dialog with fl_message_title(const char *title).
The \p title string is copied internally, so that you can use a
local variable or free the string immediately after this call.
\param[in] title default window label, string copied internally
*/
void Fl_Message::message_title_default(const char *title) {
if (message_title_default_) {
free((void *)message_title_default_);
message_title_default_ = 0;
}
if (title)
message_title_default_ = strdup(title);
}
/**
\}
\endcond
*/

160
src/Fl_Message.h Normal file
View File

@ -0,0 +1,160 @@
//
// Common dialog header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2021 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//
#ifndef _src_Fl_Message_h_
#define _src_Fl_Message_h_
#include <FL/Fl_Window.H>
#include <FL/fl_ask.H>
class Fl_Box;
class Fl_Button;
class Fl_Input;
/**
\cond DriverDev
\addtogroup DriverDeveloper
\{
*/
/**
This is the base class for all common FLTK dialog windows used in
fl_message(), fl_ask(), fl_choice(), fl_input(), and fl_password().
\note <b>Internal use only. This class may be changed as required
without notice.</b>\n
This class is reserved for FLTK's internal usage in common dialogs
in FLTK 1.4.x and later. The header file is "hidden" in the src/
folder and not installed with the public header files.
This class uses some static variables used to let the user code change
the behavior and look of the \b next call of some of the message related
functions. This is necessary to support the existing fl_message() and
similar functions and is safe as long as the variables are reset before
the function pops up (shows) the message window and enters the internal
(i.e. nested) event loop.
\since 1.4.0
*/
/* Note: Do not FL_EXPORT this class, it's for internal use only */
class Fl_Message {
// static variables and methods
private:
static Fl_Box *message_icon_; // returned by Fl_Message::message_icon()
static const char *message_title_;
static const char *message_title_default_;
// 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. :-(
// The newer functions fl_input_str() and fl_password_str() return the
// text in an Fl_String object that must be allocated and free()'d by
// the caller.
static char *input_buffer_; // points to the allocated text buffer
static int input_size_; // size of allocated text buffer
// the callback for all buttons:
static void button_cb_(Fl_Widget *w, void *d);
// the window callback:
static void window_cb_(Fl_Widget *w, void *d);
// resize to make text and buttons fit
void resizeform();
public:
static Fl_Box *message_icon();
static void message_title(const char *title);
static void message_title_default(const char *title);
/** 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) {
form_x_ = x;
form_y_ = y;
form_position_ = center ? 2 : 1;
}
/** Implements fl_message_position(Fl_Widget *widget). */
static void message_position(Fl_Widget *widget) {
form_x_ = widget->x() + widget->w() / 2;
form_y_ = widget->y() + widget->h() / 2;
form_position_ = 2;
}
/** Implements fl_message_position(int *x, int *y). */
static int message_position(int *x, int *y) {
if (x)
*x = form_position_ ? form_x_ : -1;
if (y)
*y = form_position_ ? form_y_ : -1;
return form_position_;
}
/** Implements void fl_message_hotspot(int). */
static void message_hotspot(int enable) { enable_hotspot_ = enable ? 1 : 0; }
/** Implements int fl_message_hotspot(). */
static int message_hotspot() { return enable_hotspot_; }
int window_closed() const {
return window_closed_;
}
// member variables and methods
private:
Fl_Window *window_; ///< message window
Fl_Box *message_; ///< message text
Fl_Box *icon_; ///< contains the icon
Fl_Button *button_[3]; ///< buttons used internally
Fl_Input *input_; ///< normal text or secret input
int retval_; ///< internally used to store the return value
int window_closed_; ///< window close flag (-1 = Escape, -2 = close button)
// static (private) variables
static int enable_hotspot_; ///< follow the mouse pointer (hotspot)
static int form_x_; ///< x position for next dialog
static int form_y_; ///< y position for next dialog
static int form_position_; ///< 0 = not set (may be hotspot), 1 = absolute, 2 = centered
public:
// Constructor
Fl_Message(const char *iconlabel);
/** Destructor. */
~Fl_Message() { delete window_; }
int innards(const char *fmt, va_list ap, const char *b0, const char *b1, const char *b2);
const char *input_innards(const char *fmt, va_list ap, const char *defstr, uchar type, int maxchar = -1);
};
/**
\}
\endcond
*/
#endif // _src_Fl_Message_h_

View File

@ -58,6 +58,7 @@ CPPFILES = \
Fl_Menu_Window.cxx \
Fl_Menu_add.cxx \
Fl_Menu_global.cxx \
Fl_Message.cxx \
Fl_Multi_Label.cxx \
Fl_Native_File_Chooser.cxx \
Fl_Overlay_Window.cxx \

File diff suppressed because it is too large Load Diff

View File

@ -207,7 +207,7 @@ drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/Fl_Repeat_Button.H
drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/Fl_Return_Button.H
drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/Fl_Round_Button.H
drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/Fl_Spinner.H
drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/fl_string.h
drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/Fl_String.H
drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/fl_types.h
drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/fl_utf8.h
drivers/Posix/Fl_Posix_Printer_Driver.o: ../FL/Fl_Widget.H
@ -273,7 +273,7 @@ drivers/PostScript/Fl_PostScript.o: ../FL/Fl_Plugin.H
drivers/PostScript/Fl_PostScript.o: ../FL/Fl_PostScript.H
drivers/PostScript/Fl_PostScript.o: ../FL/Fl_Preferences.H
drivers/PostScript/Fl_PostScript.o: ../FL/Fl_Return_Button.H
drivers/PostScript/Fl_PostScript.o: ../FL/fl_string.h
drivers/PostScript/Fl_PostScript.o: ../FL/Fl_String.H
drivers/PostScript/Fl_PostScript.o: ../FL/Fl_Tile.H
drivers/PostScript/Fl_PostScript.o: ../FL/fl_types.h
drivers/PostScript/Fl_PostScript.o: ../FL/fl_utf8.h
@ -397,6 +397,7 @@ drivers/X11/Fl_X11_Screen_Driver.o: ../FL/Fl_RGB_Image.H
drivers/X11/Fl_X11_Screen_Driver.o: ../FL/Fl_Scrollbar.H
drivers/X11/Fl_X11_Screen_Driver.o: ../FL/Fl_Shared_Image.H
drivers/X11/Fl_X11_Screen_Driver.o: ../FL/Fl_Slider.H
drivers/X11/Fl_X11_Screen_Driver.o: ../FL/Fl_String.H
drivers/X11/Fl_X11_Screen_Driver.o: ../FL/Fl_Text_Buffer.H
drivers/X11/Fl_X11_Screen_Driver.o: ../FL/Fl_Text_Display.H
drivers/X11/Fl_X11_Screen_Driver.o: ../FL/Fl_Text_Editor.H
@ -463,6 +464,7 @@ drivers/X11/Fl_X11_Window_Driver.o: ../FL/Fl_RGB_Image.H
drivers/X11/Fl_X11_Window_Driver.o: ../FL/Fl_Scrollbar.H
drivers/X11/Fl_X11_Window_Driver.o: ../FL/Fl_Single_Window.H
drivers/X11/Fl_X11_Window_Driver.o: ../FL/Fl_Slider.H
drivers/X11/Fl_X11_Window_Driver.o: ../FL/Fl_String.H
drivers/X11/Fl_X11_Window_Driver.o: ../FL/Fl_Text_Buffer.H
drivers/X11/Fl_X11_Window_Driver.o: ../FL/Fl_Text_Display.H
drivers/X11/Fl_X11_Window_Driver.o: ../FL/Fl_Text_Editor.H
@ -915,7 +917,6 @@ fl_ask.o: ../FL/fl_ask.H
fl_ask.o: ../FL/fl_attr.h
fl_ask.o: ../FL/Fl_Bitmap.H
fl_ask.o: ../FL/Fl_Box.H
fl_ask.o: ../FL/Fl_Button.H
fl_ask.o: ../FL/fl_casts.H
fl_ask.o: ../FL/Fl_Device.H
fl_ask.o: ../FL/fl_draw.H
@ -923,18 +924,15 @@ fl_ask.o: ../FL/Fl_Export.H
fl_ask.o: ../FL/Fl_Graphics_Driver.H
fl_ask.o: ../FL/Fl_Group.H
fl_ask.o: ../FL/Fl_Image.H
fl_ask.o: ../FL/Fl_Input.H
fl_ask.o: ../FL/Fl_Input_.H
fl_ask.o: ../FL/Fl_Pixmap.H
fl_ask.o: ../FL/Fl_Plugin.H
fl_ask.o: ../FL/Fl_Preferences.H
fl_ask.o: ../FL/Fl_Rect.H
fl_ask.o: ../FL/Fl_Return_Button.H
fl_ask.o: ../FL/Fl_RGB_Image.H
fl_ask.o: ../FL/Fl_Scrollbar.H
fl_ask.o: ../FL/Fl_Secret_Input.H
fl_ask.o: ../FL/Fl_Slider.H
fl_ask.o: ../FL/fl_string.h
fl_ask.o: ../FL/Fl_String.H
fl_ask.o: ../FL/Fl_Text_Buffer.H
fl_ask.o: ../FL/Fl_Text_Display.H
fl_ask.o: ../FL/Fl_Text_Editor.H
@ -943,9 +941,9 @@ fl_ask.o: ../FL/fl_utf8.h
fl_ask.o: ../FL/Fl_Valuator.H
fl_ask.o: ../FL/Fl_Widget.H
fl_ask.o: ../FL/Fl_Window.H
fl_ask.o: ../FL/platform.H
fl_ask.o: ../FL/platform_types.h
fl_ask.o: flstring.h
fl_ask.o: Fl_Message.h
fl_ask.o: Fl_Screen_Driver.H
Fl_Bitmap.o: ../FL/abi-version.h
Fl_Bitmap.o: ../FL/Enumerations.H
@ -1499,6 +1497,7 @@ Fl_File_Chooser.o: ../FL/Fl_Menu_Button.H
Fl_File_Chooser.o: ../FL/Fl_Menu_Item.H
Fl_File_Chooser.o: ../FL/Fl_Preferences.H
Fl_File_Chooser.o: ../FL/Fl_Return_Button.H
Fl_File_Chooser.o: ../FL/Fl_String.H
Fl_File_Chooser.o: ../FL/Fl_Tile.H
Fl_File_Chooser.o: ../FL/fl_types.h
Fl_File_Chooser.o: ../FL/fl_utf8.h
@ -1536,7 +1535,7 @@ Fl_File_Chooser2.o: ../FL/Fl_Menu_Item.H
Fl_File_Chooser2.o: ../FL/Fl_Preferences.H
Fl_File_Chooser2.o: ../FL/Fl_Return_Button.H
Fl_File_Chooser2.o: ../FL/Fl_Shared_Image.H
Fl_File_Chooser2.o: ../FL/fl_string.h
Fl_File_Chooser2.o: ../FL/Fl_String.H
Fl_File_Chooser2.o: ../FL/Fl_Tile.H
Fl_File_Chooser2.o: ../FL/fl_types.h
Fl_File_Chooser2.o: ../FL/fl_utf8.h
@ -1575,6 +1574,7 @@ fl_file_dir.o: ../FL/Fl_Menu_Button.H
fl_file_dir.o: ../FL/Fl_Menu_Item.H
fl_file_dir.o: ../FL/Fl_Preferences.H
fl_file_dir.o: ../FL/Fl_Return_Button.H
fl_file_dir.o: ../FL/Fl_String.H
fl_file_dir.o: ../FL/Fl_Tile.H
fl_file_dir.o: ../FL/fl_types.h
fl_file_dir.o: ../FL/fl_utf8.h
@ -1895,6 +1895,7 @@ Fl_Help_Dialog.o: ../FL/Fl_RGB_Image.H
Fl_Help_Dialog.o: ../FL/Fl_Scrollbar.H
Fl_Help_Dialog.o: ../FL/Fl_Shared_Image.H
Fl_Help_Dialog.o: ../FL/Fl_Slider.H
Fl_Help_Dialog.o: ../FL/Fl_String.H
Fl_Help_Dialog.o: ../FL/fl_types.h
Fl_Help_Dialog.o: ../FL/fl_utf8.h
Fl_Help_Dialog.o: ../FL/Fl_Valuator.H
@ -2020,6 +2021,7 @@ Fl_Input.o: ../FL/Fl_RGB_Image.H
Fl_Input.o: ../FL/Fl_Scrollbar.H
Fl_Input.o: ../FL/Fl_Secret_Input.H
Fl_Input.o: ../FL/Fl_Slider.H
Fl_Input.o: ../FL/Fl_String.H
Fl_Input.o: ../FL/Fl_Text_Buffer.H
Fl_Input.o: ../FL/Fl_Text_Display.H
Fl_Input.o: ../FL/Fl_Text_Editor.H
@ -2055,6 +2057,7 @@ Fl_Input_.o: ../FL/Fl_Rect.H
Fl_Input_.o: ../FL/Fl_RGB_Image.H
Fl_Input_.o: ../FL/Fl_Scrollbar.H
Fl_Input_.o: ../FL/Fl_Slider.H
Fl_Input_.o: ../FL/Fl_String.H
Fl_Input_.o: ../FL/Fl_Text_Buffer.H
Fl_Input_.o: ../FL/Fl_Text_Display.H
Fl_Input_.o: ../FL/Fl_Text_Editor.H
@ -2241,6 +2244,32 @@ Fl_Menu_Window.o: ../FL/Fl_Widget.H
Fl_Menu_Window.o: ../FL/Fl_Window.H
Fl_Menu_Window.o: ../FL/platform_types.h
Fl_Menu_Window.o: Fl_Window_Driver.H
Fl_Message.o: ../config.h
Fl_Message.o: ../FL/abi-version.h
Fl_Message.o: ../FL/Enumerations.H
Fl_Message.o: ../FL/Fl.H
Fl_Message.o: ../FL/fl_ask.H
Fl_Message.o: ../FL/fl_attr.h
Fl_Message.o: ../FL/Fl_Bitmap.H
Fl_Message.o: ../FL/Fl_Box.H
Fl_Message.o: ../FL/Fl_Button.H
Fl_Message.o: ../FL/fl_casts.H
Fl_Message.o: ../FL/fl_draw.H
Fl_Message.o: ../FL/Fl_Export.H
Fl_Message.o: ../FL/Fl_Group.H
Fl_Message.o: ../FL/Fl_Image.H
Fl_Message.o: ../FL/Fl_Input.H
Fl_Message.o: ../FL/Fl_Input_.H
Fl_Message.o: ../FL/Fl_Return_Button.H
Fl_Message.o: ../FL/Fl_Secret_Input.H
Fl_Message.o: ../FL/Fl_String.H
Fl_Message.o: ../FL/fl_types.h
Fl_Message.o: ../FL/fl_utf8.h
Fl_Message.o: ../FL/Fl_Widget.H
Fl_Message.o: ../FL/Fl_Window.H
Fl_Message.o: ../FL/platform_types.h
Fl_Message.o: flstring.h
Fl_Message.o: Fl_Message.h
Fl_Multi_Label.o: ../FL/abi-version.h
Fl_Multi_Label.o: ../FL/Enumerations.H
Fl_Multi_Label.o: ../FL/Fl.H
@ -2282,6 +2311,7 @@ Fl_Native_File_Chooser.o: ../FL/Fl_Menu_Item.H
Fl_Native_File_Chooser.o: ../FL/Fl_Native_File_Chooser.H
Fl_Native_File_Chooser.o: ../FL/Fl_Preferences.H
Fl_Native_File_Chooser.o: ../FL/Fl_Return_Button.H
Fl_Native_File_Chooser.o: ../FL/Fl_String.H
Fl_Native_File_Chooser.o: ../FL/Fl_Tile.H
Fl_Native_File_Chooser.o: ../FL/fl_types.h
Fl_Native_File_Chooser.o: ../FL/fl_utf8.h
@ -2317,6 +2347,7 @@ Fl_Native_File_Chooser_FLTK.o: ../FL/Fl_Menu_Item.H
Fl_Native_File_Chooser_FLTK.o: ../FL/Fl_Native_File_Chooser.H
Fl_Native_File_Chooser_FLTK.o: ../FL/Fl_Preferences.H
Fl_Native_File_Chooser_FLTK.o: ../FL/Fl_Return_Button.H
Fl_Native_File_Chooser_FLTK.o: ../FL/Fl_String.H
Fl_Native_File_Chooser_FLTK.o: ../FL/Fl_Tile.H
Fl_Native_File_Chooser_FLTK.o: ../FL/fl_types.h
Fl_Native_File_Chooser_FLTK.o: ../FL/fl_utf8.h
@ -2360,7 +2391,7 @@ Fl_Native_File_Chooser_GTK.o: ../FL/Fl_Plugin.H
Fl_Native_File_Chooser_GTK.o: ../FL/Fl_Preferences.H
Fl_Native_File_Chooser_GTK.o: ../FL/Fl_Return_Button.H
Fl_Native_File_Chooser_GTK.o: ../FL/Fl_Shared_Image.H
Fl_Native_File_Chooser_GTK.o: ../FL/fl_string.h
Fl_Native_File_Chooser_GTK.o: ../FL/Fl_String.H
Fl_Native_File_Chooser_GTK.o: ../FL/Fl_Tile.H
Fl_Native_File_Chooser_GTK.o: ../FL/fl_types.h
Fl_Native_File_Chooser_GTK.o: ../FL/fl_utf8.h
@ -2932,7 +2963,7 @@ fl_string.o: ../FL/Fl.H
fl_string.o: ../FL/fl_casts.H
fl_string.o: ../FL/Fl_Export.H
fl_string.o: ../FL/Fl_Preferences.H
fl_string.o: ../FL/fl_string.h
Fl_String.o: ../FL/Fl_String.H
fl_string.o: ../FL/fl_types.h
fl_string.o: ../FL/fl_utf8.h
fl_string.o: ../FL/platform_types.h
@ -3128,6 +3159,7 @@ Fl_Text_Editor.o: ../FL/Fl_Rect.H
Fl_Text_Editor.o: ../FL/Fl_RGB_Image.H
Fl_Text_Editor.o: ../FL/Fl_Scrollbar.H
Fl_Text_Editor.o: ../FL/Fl_Slider.H
Fl_Text_Editor.o: ../FL/Fl_String.H
Fl_Text_Editor.o: ../FL/Fl_Text_Buffer.H
Fl_Text_Editor.o: ../FL/Fl_Text_Display.H
Fl_Text_Editor.o: ../FL/Fl_Text_Editor.H
@ -3565,6 +3597,7 @@ Fl_x.o: ../FL/Fl_RGB_Image.H
Fl_x.o: ../FL/Fl_Scrollbar.H
Fl_x.o: ../FL/Fl_Shared_Image.H
Fl_x.o: ../FL/Fl_Slider.H
Fl_x.o: ../FL/Fl_String.H
Fl_x.o: ../FL/Fl_Text_Buffer.H
Fl_x.o: ../FL/Fl_Text_Display.H
Fl_x.o: ../FL/Fl_Text_Editor.H
@ -3661,6 +3694,7 @@ forms_bitmap.o: ../FL/Fl_RGB_Image.H
forms_bitmap.o: ../FL/Fl_Round_Button.H
forms_bitmap.o: ../FL/fl_show_colormap.H
forms_bitmap.o: ../FL/Fl_Slider.H
forms_bitmap.o: ../FL/Fl_String.H
forms_bitmap.o: ../FL/Fl_Tile.H
forms_bitmap.o: ../FL/Fl_Timer.H
forms_bitmap.o: ../FL/fl_types.h
@ -3719,6 +3753,7 @@ forms_compatibility.o: ../FL/Fl_RGB_Image.H
forms_compatibility.o: ../FL/Fl_Round_Button.H
forms_compatibility.o: ../FL/fl_show_colormap.H
forms_compatibility.o: ../FL/Fl_Slider.H
forms_compatibility.o: ../FL/Fl_String.H
forms_compatibility.o: ../FL/Fl_Tile.H
forms_compatibility.o: ../FL/Fl_Timer.H
forms_compatibility.o: ../FL/fl_types.h
@ -3787,6 +3822,7 @@ forms_fselect.o: ../FL/Fl_RGB_Image.H
forms_fselect.o: ../FL/Fl_Round_Button.H
forms_fselect.o: ../FL/fl_show_colormap.H
forms_fselect.o: ../FL/Fl_Slider.H
forms_fselect.o: ../FL/Fl_String.H
forms_fselect.o: ../FL/Fl_Tile.H
forms_fselect.o: ../FL/Fl_Timer.H
forms_fselect.o: ../FL/fl_types.h
@ -3845,6 +3881,7 @@ forms_pixmap.o: ../FL/Fl_RGB_Image.H
forms_pixmap.o: ../FL/Fl_Round_Button.H
forms_pixmap.o: ../FL/fl_show_colormap.H
forms_pixmap.o: ../FL/Fl_Slider.H
forms_pixmap.o: ../FL/Fl_String.H
forms_pixmap.o: ../FL/Fl_Tile.H
forms_pixmap.o: ../FL/Fl_Timer.H
forms_pixmap.o: ../FL/fl_types.h
@ -3902,6 +3939,7 @@ forms_timer.o: ../FL/Fl_RGB_Image.H
forms_timer.o: ../FL/Fl_Round_Button.H
forms_timer.o: ../FL/fl_show_colormap.H
forms_timer.o: ../FL/Fl_Slider.H
forms_timer.o: ../FL/Fl_String.H
forms_timer.o: ../FL/Fl_Tile.H
forms_timer.o: ../FL/Fl_Timer.H
forms_timer.o: ../FL/fl_types.h

View File

@ -4,7 +4,7 @@
// This also demonstrates how to trap attempts by the user to
// close the last window by overriding Fl::exit
//
// Copyright 1998-2017 by Bill Spitzak and others.
// Copyright 1998-2021 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -17,10 +17,6 @@
// https://www.fltk.org/bugs.php
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Input.H>
@ -30,33 +26,34 @@
#include <FL/fl_ask.H>
void update_input_text(Fl_Widget* o, const char *input) {
if (input) {
o->copy_label(input);
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// Button callback: v == 0 ("input") or 1 ("password")
void rename_button(Fl_Widget *o, void *v) {
int what = fl_int(v);
Fl_String input;
if (what == 0)
input = fl_input_str(0, "Input (no size limit, use ctrl/j for newline):", o->label());
else
input = fl_password_str(20, "Enter password (max. 20 characters):", o->label());
if (input.value()) {
o->copy_label(input.value());
o->redraw();
}
}
void rename_me(Fl_Widget*o) {
const char *input = fl_input("Input:", o->label());
update_input_text(o, input);
}
void rename_me_pwd(Fl_Widget*o) {
const char *input = fl_password("Input PWD:", o->label());
update_input_text(o, input);
}
void window_callback(Fl_Widget *win, void*) {
void window_callback(Fl_Widget *win, void *) {
int hotspot = fl_message_hotspot();
fl_message_hotspot(0);
fl_message_title("note: no hotspot set for this dialog");
int rep = fl_choice("Are you sure you want to quit?",
"Cancel", "Quit", "Dunno");
int rep = fl_choice("Are you sure you want to quit?", "Cancel", "Quit", "Dunno");
fl_message_hotspot(hotspot);
if (rep==1)
if (rep == 1)
exit(0);
else if (rep==2) { // (Dunno)
else if (rep == 2) { // (Dunno)
fl_message_position(win);
fl_message_title("This dialog must be centered over the main window");
fl_message("Well, maybe you should know before we quit.");
@ -65,45 +62,61 @@ void window_callback(Fl_Widget *win, void*) {
/*
This timer callback shows a message dialog (fl_choice) window
every 5 seconds to test "recursive" common dialogs.
every 5 seconds to test "recursive" (aka nested) common dialogs.
The timer can be stopped by clicking the button "Stop these funny popups"
or pressing the Enter key. As it is currently implemented, clicking the
"Close" button will reactivate the popups (only possible if "recursive"
dialogs are enabled, see below).
Note 1: This dialog box is blocked in FLTK 1.3.x if another common dialog
is already open because the window used is a static (i.e. permanently
allocated) Fl_Window instance. This should be fixed in FLTK 1.4.0.
Note 1: This dialog box had been blocked in FLTK 1.3.x if another common
dialog was already open because the window used was a static (i.e. permanently
allocated) Fl_Window instance. This has been fixed in FLTK 1.4.0.
See STR #334 (sic !) and also STR #2751 ("Limit input field characters").
*/
void timer_cb(void *) {
static int stop = 0;
static const double delta = 5.0;
static int n = 0;
const double delta = 5.0; // delay of popups
const int nmax = 10; // limit no. of popups
n++;
if (n >= nmax)
stop = 1;
Fl_Box *message_icon = (Fl_Box *)fl_message_icon();
Fl::repeat_timeout(delta, timer_cb);
if (stop == 1) {
if (stop) {
message_icon->color(FL_WHITE);
return;
}
Fl::repeat_timeout(delta, timer_cb);
// Change the icon box color:
Fl_Color c = message_icon->color();
c = (c+1) % 32;
if (c == message_icon->labelcolor()) c++;
c = (c + 1) % 32;
if (c == message_icon->labelcolor())
c++;
message_icon->color((Fl_Color)c);
// test message title assignment with a local buffer
{ // local scope for buf
char buf[40]; // test: use local variable
sprintf(buf, "Message #%d", n); // fill message title
fl_message_title(buf); // set message title
strcpy(buf, "** void **"); // overwrite buffer to be sure
} // buf goes out of scope here
// pop up a message:
stop = fl_choice("Timeout. Click the 'Close' button.\n"
"Note: this message was blocked in FLTK 1.3\n"
"if another message window is open.\n"
"This *should* be fixed in FLTK 1.4.0!\n"
"This message should pop up every 5 seconds.",
"Close", "Stop these funny popups", NULL);
stop |= fl_choice(
"Timeout. Click the 'Close' button or press Escape.\n"
"Note: this message had been blocked in FLTK 1.3.x\n"
"and earlier if another message window was open.\n"
"This message should pop up every 5 seconds (max. 10 times)\n"
"in FLTK 1.4.0 and later until stopped by clicking the button\n"
"below or by pressing the Enter (Return) key.\n",
"Close", "Stop these funny popups", NULL);
}
int main(int argc, char **argv) {
@ -115,9 +128,9 @@ int main(int argc, char **argv) {
Fl_Double_Window window(200, 105);
Fl_Return_Button b(20, 10, 160, 35, buffer);
b.callback(rename_me);
b.callback(rename_button, (void *)(0));
Fl_Button b2(20, 50, 160, 35, buffer2);
b2.callback(rename_me_pwd);
b2.callback(rename_button, (void *)(1));
window.end();
window.resizable(&b);
window.show(argc, argv);
@ -126,9 +139,9 @@ int main(int argc, char **argv) {
window.callback(window_callback);
// Test: set default message window title:
// fl_message_title_default("Default Window Title");
// fl_message_title_default("Default Message Title");
// Test: multiple (nested, aka "recursive") popups
// Test: multiple (nested, aka "recursive") popups (see timer_cb())
Fl::add_timeout(5.0, timer_cb);
return Fl::run();

View File

@ -83,6 +83,7 @@ ask.o: ../FL/Fl_Image.H
ask.o: ../FL/Fl_Input.H
ask.o: ../FL/Fl_Input_.H
ask.o: ../FL/Fl_Return_Button.H
ask.o: ../FL/Fl_String.H
ask.o: ../FL/fl_types.h
ask.o: ../FL/fl_utf8.h
ask.o: ../FL/Fl_Widget.H
@ -203,6 +204,7 @@ browser.o: ../FL/Fl_Scrollbar.H
browser.o: ../FL/Fl_Select_Browser.H
browser.o: ../FL/Fl_Simple_Terminal.H
browser.o: ../FL/Fl_Slider.H
browser.o: ../FL/Fl_String.H
browser.o: ../FL/Fl_Text_Buffer.H
browser.o: ../FL/Fl_Text_Display.H
browser.o: ../FL/fl_types.h
@ -222,6 +224,7 @@ button.o: ../FL/fl_casts.H
button.o: ../FL/Fl_Export.H
button.o: ../FL/Fl_Group.H
button.o: ../FL/Fl_Image.H
button.o: ../FL/Fl_String.H
button.o: ../FL/fl_types.h
button.o: ../FL/fl_utf8.h
button.o: ../FL/Fl_Widget.H
@ -297,6 +300,7 @@ checkers.o: ../FL/Fl_Preferences.H
checkers.o: ../FL/Fl_Rect.H
checkers.o: ../FL/Fl_RGB_Image.H
checkers.o: ../FL/Fl_Slider.H
checkers.o: ../FL/Fl_String.H
checkers.o: ../FL/fl_types.h
checkers.o: ../FL/fl_utf8.h
checkers.o: ../FL/Fl_Valuator.H
@ -347,6 +351,7 @@ clipboard.o: ../FL/Fl_RGB_Image.H
clipboard.o: ../FL/Fl_Scrollbar.H
clipboard.o: ../FL/Fl_Shared_Image.H
clipboard.o: ../FL/Fl_Slider.H
clipboard.o: ../FL/Fl_String.H
clipboard.o: ../FL/Fl_Tabs.H
clipboard.o: ../FL/Fl_Text_Buffer.H
clipboard.o: ../FL/Fl_Text_Display.H
@ -392,6 +397,7 @@ colbrowser.o: ../FL/Fl_Hold_Browser.H
colbrowser.o: ../FL/Fl_Image.H
colbrowser.o: ../FL/Fl_Scrollbar.H
colbrowser.o: ../FL/Fl_Slider.H
colbrowser.o: ../FL/Fl_String.H
colbrowser.o: ../FL/fl_types.h
colbrowser.o: ../FL/fl_utf8.h
colbrowser.o: ../FL/Fl_Valuator.H
@ -595,6 +601,7 @@ demo.o: ../FL/Fl_RGB_Image.H
demo.o: ../FL/Fl_Scrollbar.H
demo.o: ../FL/Fl_Simple_Terminal.H
demo.o: ../FL/Fl_Slider.H
demo.o: ../FL/Fl_String.H
demo.o: ../FL/Fl_Text_Buffer.H
demo.o: ../FL/Fl_Text_Display.H
demo.o: ../FL/fl_types.h
@ -653,6 +660,7 @@ device.o: ../FL/Fl_Round_Button.H
device.o: ../FL/Fl_Scrollbar.H
device.o: ../FL/Fl_Shared_Image.H
device.o: ../FL/Fl_Slider.H
device.o: ../FL/Fl_String.H
device.o: ../FL/Fl_SVG_File_Surface.H
device.o: ../FL/Fl_Tile.H
device.o: ../FL/fl_types.h
@ -733,6 +741,7 @@ editor.o: ../FL/Fl_Return_Button.H
editor.o: ../FL/Fl_RGB_Image.H
editor.o: ../FL/Fl_Scrollbar.H
editor.o: ../FL/Fl_Slider.H
editor.o: ../FL/Fl_String.H
editor.o: ../FL/Fl_Text_Buffer.H
editor.o: ../FL/Fl_Text_Display.H
editor.o: ../FL/Fl_Text_Editor.H
@ -804,6 +813,7 @@ file_chooser.o: ../FL/Fl_Scrollbar.H
file_chooser.o: ../FL/Fl_Shared_Image.H
file_chooser.o: ../FL/Fl_Simple_Terminal.H
file_chooser.o: ../FL/Fl_Slider.H
file_chooser.o: ../FL/Fl_String.H
file_chooser.o: ../FL/Fl_Text_Buffer.H
file_chooser.o: ../FL/Fl_Text_Display.H
file_chooser.o: ../FL/Fl_Tile.H
@ -824,6 +834,7 @@ fltk-versions.o: ../FL/fl_casts.H
fltk-versions.o: ../FL/Fl_Export.H
fltk-versions.o: ../FL/Fl_Group.H
fltk-versions.o: ../FL/Fl_Image.H
fltk-versions.o: ../FL/Fl_String.H
fltk-versions.o: ../FL/fl_types.h
fltk-versions.o: ../FL/fl_utf8.h
fltk-versions.o: ../FL/Fl_Widget.H
@ -869,6 +880,7 @@ fonts.o: ../FL/Fl_Return_Button.H
fonts.o: ../FL/Fl_RGB_Image.H
fonts.o: ../FL/Fl_Scrollbar.H
fonts.o: ../FL/Fl_Slider.H
fonts.o: ../FL/Fl_String.H
fonts.o: ../FL/Fl_Tile.H
fonts.o: ../FL/fl_types.h
fonts.o: ../FL/fl_utf8.h
@ -925,6 +937,7 @@ forms.o: ../FL/Fl_Round_Button.H
forms.o: ../FL/Fl_Scrollbar.H
forms.o: ../FL/fl_show_colormap.H
forms.o: ../FL/Fl_Slider.H
forms.o: ../FL/Fl_String.H
forms.o: ../FL/Fl_Tile.H
forms.o: ../FL/Fl_Timer.H
forms.o: ../FL/fl_types.h
@ -1000,6 +1013,7 @@ fullscreen.o: ../FL/Fl_Menu_Item.H
fullscreen.o: ../FL/Fl_Scrollbar.H
fullscreen.o: ../FL/Fl_Single_Window.H
fullscreen.o: ../FL/Fl_Slider.H
fullscreen.o: ../FL/Fl_String.H
fullscreen.o: ../FL/Fl_Toggle_Light_Button.H
fullscreen.o: ../FL/fl_types.h
fullscreen.o: ../FL/fl_utf8.h
@ -1416,7 +1430,7 @@ menubar.o: ../FL/Fl_RGB_Image.H
menubar.o: ../FL/Fl_Scrollbar.H
menubar.o: ../FL/Fl_Simple_Terminal.H
menubar.o: ../FL/Fl_Slider.H
menubar.o: ../FL/fl_string.h
menubar.o: ../FL/Fl_String.H
menubar.o: ../FL/Fl_Sys_Menu_Bar.H
menubar.o: ../FL/Fl_Text_Buffer.H
menubar.o: ../FL/Fl_Text_Display.H
@ -1438,6 +1452,7 @@ message.o: ../FL/fl_casts.H
message.o: ../FL/Fl_Export.H
message.o: ../FL/Fl_Group.H
message.o: ../FL/Fl_Image.H
message.o: ../FL/Fl_String.H
message.o: ../FL/fl_types.h
message.o: ../FL/fl_utf8.h
message.o: ../FL/Fl_Widget.H
@ -1505,6 +1520,7 @@ native-filechooser.o: ../FL/Fl_RGB_Image.H
native-filechooser.o: ../FL/Fl_Scrollbar.H
native-filechooser.o: ../FL/Fl_Simple_Terminal.H
native-filechooser.o: ../FL/Fl_Slider.H
native-filechooser.o: ../FL/Fl_String.H
native-filechooser.o: ../FL/Fl_Text_Buffer.H
native-filechooser.o: ../FL/Fl_Text_Display.H
native-filechooser.o: ../FL/Fl_Tile.H
@ -1693,6 +1709,7 @@ pixmap_browser.o: ../FL/Fl_Return_Button.H
pixmap_browser.o: ../FL/Fl_Scrollbar.H
pixmap_browser.o: ../FL/Fl_Shared_Image.H
pixmap_browser.o: ../FL/Fl_Slider.H
pixmap_browser.o: ../FL/Fl_String.H
pixmap_browser.o: ../FL/Fl_SVG_File_Surface.H
pixmap_browser.o: ../FL/Fl_Tile.H
pixmap_browser.o: ../FL/fl_types.h
@ -1727,6 +1744,7 @@ preferences.o: ../FL/Fl_Menu_Item.H
preferences.o: ../FL/Fl_Preferences.H
preferences.o: ../FL/Fl_Round_Button.H
preferences.o: ../FL/Fl_Slider.H
preferences.o: ../FL/Fl_String.H
preferences.o: ../FL/fl_types.h
preferences.o: ../FL/fl_utf8.h
preferences.o: ../FL/Fl_Valuator.H
@ -1961,6 +1979,7 @@ resizebox.o: ../FL/Fl_Preferences.H
resizebox.o: ../FL/Fl_Radio_Button.H
resizebox.o: ../FL/Fl_Rect.H
resizebox.o: ../FL/Fl_RGB_Image.H
resizebox.o: ../FL/Fl_String.H
resizebox.o: ../FL/fl_types.h
resizebox.o: ../FL/fl_utf8.h
resizebox.o: ../FL/Fl_Widget.H
@ -2107,6 +2126,7 @@ sudoku.o: ../FL/Fl_RGB_Image.H
sudoku.o: ../FL/Fl_Scrollbar.H
sudoku.o: ../FL/Fl_Shared_Image.H
sudoku.o: ../FL/Fl_Slider.H
sudoku.o: ../FL/Fl_String.H
sudoku.o: ../FL/Fl_Sys_Menu_Bar.H
sudoku.o: ../FL/fl_types.h
sudoku.o: ../FL/fl_utf8.h
@ -2174,6 +2194,7 @@ table.o: ../FL/Fl_Scroll.H
table.o: ../FL/Fl_Scrollbar.H
table.o: ../FL/Fl_Simple_Terminal.H
table.o: ../FL/Fl_Slider.H
table.o: ../FL/Fl_String.H
table.o: ../FL/Fl_Table.H
table.o: ../FL/Fl_Table_Row.H
table.o: ../FL/Fl_Text_Buffer.H
@ -2201,6 +2222,7 @@ tabs.o: ../FL/Fl_Image.H
tabs.o: ../FL/Fl_Input.H
tabs.o: ../FL/Fl_Input_.H
tabs.o: ../FL/Fl_Return_Button.H
tabs.o: ../FL/Fl_String.H
tabs.o: ../FL/Fl_Tabs.H
tabs.o: ../FL/fl_types.h
tabs.o: ../FL/fl_utf8.h
@ -2225,6 +2247,7 @@ threads.o: ../FL/Fl_Group.H
threads.o: ../FL/Fl_Image.H
threads.o: ../FL/Fl_Scrollbar.H
threads.o: ../FL/Fl_Slider.H
threads.o: ../FL/Fl_String.H
threads.o: ../FL/fl_types.h
threads.o: ../FL/fl_utf8.h
threads.o: ../FL/Fl_Valuator.H
@ -2312,6 +2335,7 @@ tree.o: ../FL/Fl_RGB_Image.H
tree.o: ../FL/Fl_Scrollbar.H
tree.o: ../FL/Fl_Simple_Terminal.H
tree.o: ../FL/Fl_Slider.H
tree.o: ../FL/Fl_String.H
tree.o: ../FL/Fl_Text_Buffer.H
tree.o: ../FL/Fl_Text_Display.H
tree.o: ../FL/Fl_Tile.H