|
|
commit f6c2531b5b4d939352dccd9f8295f4471d7e1c4c
Author: Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Wed Feb 9 16:32:48 2022 +0100
Commit: Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Wed Feb 9 16:33:55 2022 +0100
Enable end user to copy standard dialog text to clipboard (#388)
All standard dialogs like fl_message() now handle command-c (macOS)
and ctrl-c (other platforms) to copy the message text of standard
dialogs to the clipboard as requested by GitHub Issue #388.
src/Fl_Message.cxx | 22 ++++++++++++++++++++--
src/Fl_Message.h | 34 +++++++++++++++++++++++++---------
2 files changed, 45 insertions(+), 11 deletions(-)
diff --git src/Fl_Message.cxx src/Fl_Message.cxx
index 5c27d2f..970dde3 100644
--- src/Fl_Message.cxx
+++ 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 src/Fl_Message.h src/Fl_Message.h
index 7e6cfd6..7450d23 100644
--- src/Fl_Message.h
+++ 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
[ Direct Link to Message ] | |
|
| |