mirror of
https://github.com/fltk/fltk.git
synced 2026-05-27 02:46:34 +08:00
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.
This commit is contained in:
+20
-2
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Common dialog implementation for the Fast Light Tool Kit (FLTK).
|
// 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
|
// 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
|
// 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
|
// create widgets
|
||||||
|
|
||||||
window_ = new Fl_Window(400, 150, NULL);
|
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);
|
message_->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
|
||||||
|
|
||||||
input_ = new Fl_Input(60, 37, 340, 23);
|
input_ = new Fl_Input(60, 37, 340, 23);
|
||||||
@@ -544,6 +544,24 @@ void Fl_Message::icon_label(const char *str) {
|
|||||||
message_icon_label_ = 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
|
\endcond
|
||||||
|
|||||||
+25
-9
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Common dialog header file for the Fast Light Tool Kit (FLTK).
|
// 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
|
// 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
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
@@ -18,9 +18,9 @@
|
|||||||
#define _src_Fl_Message_h_
|
#define _src_Fl_Message_h_
|
||||||
|
|
||||||
#include <FL/Fl_Window.H>
|
#include <FL/Fl_Window.H>
|
||||||
|
#include <FL/Fl_Box.H>
|
||||||
#include <FL/fl_ask.H>
|
#include <FL/fl_ask.H>
|
||||||
|
|
||||||
class Fl_Box;
|
|
||||||
class Fl_Button;
|
class Fl_Button;
|
||||||
class Fl_Input;
|
class Fl_Input;
|
||||||
|
|
||||||
@@ -32,6 +32,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
|
This is the base class for all common FLTK dialog windows used in
|
||||||
fl_message(), fl_ask(), fl_choice(), fl_input(), and fl_password().
|
fl_message(), fl_ask(), fl_choice(), fl_input(), and fl_password().
|
||||||
@@ -130,13 +146,13 @@ public:
|
|||||||
// member variables and methods
|
// member variables and methods
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Fl_Window *window_; ///< message window
|
Fl_Window *window_; ///< message window
|
||||||
Fl_Box *message_; ///< message text
|
Fl_Message_Box *message_; ///< message text (handles ctrl-c)
|
||||||
Fl_Box *icon_; ///< contains the icon
|
Fl_Box *icon_; ///< contains the icon
|
||||||
Fl_Button *button_[3]; ///< buttons used internally
|
Fl_Button *button_[3]; ///< buttons used internally
|
||||||
Fl_Input *input_; ///< normal text or secret input
|
Fl_Input *input_; ///< normal text or secret input
|
||||||
int retval_; ///< internally used to store the return value
|
int retval_; ///< internally used to store the return value
|
||||||
int window_closed_; ///< window close flag (-1 = Escape, -2 = close button)
|
int window_closed_; ///< window close flag (-1 = Escape, -2 = close button)
|
||||||
|
|
||||||
// static (private) variables
|
// static (private) variables
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user