From 7fcc9a87b4a4a482afb8e0fe9edf1291670cbcbd Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 25 Apr 2002 18:06:15 +0000
Subject: [PATCH] Add "copy to clipboard" functionality to the File->Message
 window

---
 Fltk/Callbacks.cpp | 24 +++++++++++++++++++++++-
 Fltk/Callbacks.h   |  1 +
 Fltk/GUI.cpp       |  4 +++-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index b0aeaafcb9..6ee5c7ef7f 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.118 2002-04-23 23:07:23 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.119 2002-04-25 18:06:15 geuzaine Exp $
 
 #include <sys/types.h>
 #include <signal.h>
@@ -596,6 +596,28 @@ void opt_statistics_histogram_cb(CALLBACK_ARGS) {
 void opt_message_cb(CALLBACK_ARGS) {
   WID->create_message_window();
 }
+void opt_message_copy_cb(CALLBACK_ARGS) {
+#if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 0)
+  // Fl::copy does not exist in older versions of fltk
+#else
+#define BUFFL 50000
+  static char buff[BUFFL];
+  strcpy(buff, "");
+  for(int i = 1 ; i<=WID->msg_browser->size() ; i++){
+    if(WID->msg_browser->selected(i)){
+      const char *c=WID->msg_browser->text(i);
+      if(strlen(buff)+strlen(c)>BUFFL-2){
+	Msg(GERROR, "Text selection too large to copy");
+	break;
+      }
+      if(c[0]=='@') strcat(buff,&c[3]);
+      else strcat(buff, c);
+      strcat(buff, "\n");
+    }
+  }
+  Fl::copy(buff, strlen(buff), 0);
+#endif
+}
 void opt_message_clear_cb(CALLBACK_ARGS) {
   WID->msg_browser->clear();
 }
diff --git a/Fltk/Callbacks.h b/Fltk/Callbacks.h
index 3c02cf672f..4acfd60b33 100644
--- a/Fltk/Callbacks.h
+++ b/Fltk/Callbacks.h
@@ -83,6 +83,7 @@ void opt_statistics_histogram_cb(CALLBACK_ARGS) ;
 // Option Message Menu
 
 void opt_message_cb(CALLBACK_ARGS) ;
+void opt_message_copy_cb(CALLBACK_ARGS) ;
 void opt_message_clear_cb(CALLBACK_ARGS) ;
 void opt_message_save_cb(CALLBACK_ARGS) ;
 
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 866a4427ca..2f22b8cedc 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.169 2002-04-25 04:30:35 geuzaine Exp $
+// $Id: GUI.cpp,v 1.170 2002-04-25 18:06:15 geuzaine Exp $
 
 // To make the interface as visually consistent as possible, please:
 // - use the IW, BB, BH, BW and WB values
@@ -1920,6 +1920,8 @@ void GUI::create_message_window(){
   
   msg_browser = new Fl_Browser(WB, WB, width-2*WB, height-3*WB-BH);
   msg_browser->textfont(FL_COURIER);
+  msg_browser->type(FL_MULTI_BROWSER);
+  msg_browser->callback(opt_message_copy_cb);
   
   { 
     Fl_Return_Button* o = new Fl_Return_Button(width-3*BB-3*WB, height-BH-WB, BB, BH, "Save");
-- 
GitLab