diff options
| -rw-r--r-- | src/Fl_Message.cxx | 22 | ||||
| -rw-r--r-- | src/Fl_Message.h | 34 |
2 files changed, 45 insertions, 11 deletions
diff --git a/src/Fl_Message.cxx b/src/Fl_Message.cxx index 5c27d2f89..970dde3f4 100644 --- a/src/Fl_Message.cxx +++ b/src/Fl_Message.cxx @@ -1,7 +1,7 @@ // // Common dialog implementation for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2021 by Bill Spitzak and others. +// Copyright 1998-2022 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 @@ -149,7 +149,7 @@ Fl_Message::Fl_Message(const char *iconlabel) // create widgets window_ = new Fl_Window(400, 150, NULL); - message_ = new Fl_Box(60, 25, 340, 20); + message_ = new Fl_Message_Box(60, 25, 340, 20); message_->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_WRAP); input_ = new Fl_Input(60, 37, 340, 23); @@ -544,6 +544,24 @@ void Fl_Message::icon_label(const char *str) { message_icon_label_ = str; } +// handle ctrl-c (command-c on macOS) to copy message text + +int Fl_Message_Box::handle(int e) { + unsigned int mods = Fl::event_state() & (FL_META|FL_CTRL|FL_ALT); + switch (e) { + case FL_KEYBOARD: + case FL_SHORTCUT: + if (Fl::event_key() == 'c' && mods == FL_COMMAND) { + Fl::copy(label(), strlen(label()), 1); + return 1; + } + break; + default: + break; + } + return Fl_Box::handle(e); +} + /** \} \endcond diff --git a/src/Fl_Message.h b/src/Fl_Message.h index 7e6cfd623..7450d23a1 100644 --- a/src/Fl_Message.h +++ b/src/Fl_Message.h @@ -1,7 +1,7 @@ // // Common dialog header file for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2021 by Bill Spitzak and others. +// Copyright 1998-2022 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,9 +18,9 @@ #define _src_Fl_Message_h_ #include <FL/Fl_Window.H> +#include <FL/Fl_Box.H> #include <FL/fl_ask.H> -class Fl_Box; class Fl_Button; class Fl_Input; @@ -33,6 +33,22 @@ class Fl_Input; */ /** + Fl_Message_Box is a tiny class that features copying the message text. + + This class is used in Fl_Message and handles ctrl-c or command-c + (on macOS) to copy the given message text to the clipboard. +*/ + +/* Note: Do not FL_EXPORT this class, it's for internal use only */ + +class Fl_Message_Box : public Fl_Box { +public: + Fl_Message_Box(int X, int Y, int W, int H) + : Fl_Box(X, Y, W, H) {} + int handle(int e); +}; // class Fl_Message_Box + +/** This is the base class for all common FLTK dialog windows used in fl_message(), fl_ask(), fl_choice(), fl_input(), and fl_password(). @@ -130,13 +146,13 @@ public: // 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) + Fl_Window *window_; ///< message window + Fl_Message_Box *message_; ///< message text (handles ctrl-c) + 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 |
