mirror of
https://github.com/fltk/fltk.git
synced 2026-05-27 10:57:58 +08:00
Extend commit a4b33f8 to other uses of function convert_crlf()
Helper function convert_crlf() from file fl_wayland_clipboard_dnd.cxx has been
repaired by commit a4b33f8 (13 jan 2023). But the same function was also in
file Fl_cocoa.mm. This commit moves the repaired code to class Fl_Screen_Driver
and has both fl_wayland_clipboard_dnd.cxx and Fl_cocoa.mm use it.
This commit is contained in:
@@ -197,6 +197,7 @@ public:
|
|||||||
static void write_image_inside(Fl_RGB_Image *to, Fl_RGB_Image *from, int to_x, int to_y);
|
static void write_image_inside(Fl_RGB_Image *to, Fl_RGB_Image *from, int to_x, int to_y);
|
||||||
static Fl_RGB_Image *traverse_to_gl_subwindows(Fl_Group *g, int x, int y, int w, int h,
|
static Fl_RGB_Image *traverse_to_gl_subwindows(Fl_Group *g, int x, int y, int w, int h,
|
||||||
Fl_RGB_Image *full_img);
|
Fl_RGB_Image *full_img);
|
||||||
|
static size_t convert_crlf(char *s, size_t len);
|
||||||
// optional platform-specific key handling for Fl_Input widget
|
// optional platform-specific key handling for Fl_Input widget
|
||||||
// the default implementation may be enough
|
// the default implementation may be enough
|
||||||
virtual int input_widget_handle_key(int key, unsigned mods, unsigned shift, Fl_Input *input);
|
virtual int input_widget_handle_key(int key, unsigned mods, unsigned shift, Fl_Input *input);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <FL/Fl_Image_Surface.H>
|
#include <FL/Fl_Image_Surface.H>
|
||||||
#include <FL/Fl_Box.H>
|
#include <FL/Fl_Box.H>
|
||||||
#include <FL/Fl_Tooltip.H>
|
#include <FL/Fl_Tooltip.H>
|
||||||
|
#include <string.h> // for memchr
|
||||||
|
|
||||||
char Fl_Screen_Driver::bg_set = 0;
|
char Fl_Screen_Driver::bg_set = 0;
|
||||||
char Fl_Screen_Driver::bg2_set = 0;
|
char Fl_Screen_Driver::bg2_set = 0;
|
||||||
@@ -709,6 +710,32 @@ int Fl_Screen_Driver::XParseGeometry(const char* string, int* x, int* y,
|
|||||||
return (mask);
|
return (mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// turn '\r' characters into '\n' and "\r\n" sequences into '\n'
|
||||||
|
// returns new length
|
||||||
|
size_t Fl_Screen_Driver::convert_crlf(char *s, size_t len) {
|
||||||
|
char *src = (char *)memchr(s, '\r', len); // find first `\r` in buffer
|
||||||
|
if (src) {
|
||||||
|
char *dst = src;
|
||||||
|
char *end = s + len;
|
||||||
|
while (src < end) {
|
||||||
|
if (*src == '\r') {
|
||||||
|
if (src + 1 < end && *(src + 1) == '\n') {
|
||||||
|
src++; // skip '\r'
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
*dst++ = '\n'; // replace single '\r' with '\n'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*dst++ = *src;
|
||||||
|
}
|
||||||
|
src++;
|
||||||
|
}
|
||||||
|
return (dst - s);
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\}
|
\}
|
||||||
\endcond
|
\endcond
|
||||||
|
|||||||
+2
-19
@@ -67,7 +67,6 @@ extern int fl_send_system_handlers(void *e);
|
|||||||
|
|
||||||
// forward definition of functions in this file
|
// forward definition of functions in this file
|
||||||
// converting cr lf converter function
|
// converting cr lf converter function
|
||||||
static size_t convert_crlf(char * string, size_t len);
|
|
||||||
static void createAppleMenu(void);
|
static void createAppleMenu(void);
|
||||||
static void cocoaMouseHandler(NSEvent *theEvent);
|
static void cocoaMouseHandler(NSEvent *theEvent);
|
||||||
static void clipboard_check(void);
|
static void clipboard_check(void);
|
||||||
@@ -2547,7 +2546,7 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
|||||||
DragData = (char *)malloc([data length] + 1);
|
DragData = (char *)malloc([data length] + 1);
|
||||||
[data getBytes:DragData];
|
[data getBytes:DragData];
|
||||||
DragData[[data length]] = 0;
|
DragData[[data length]] = 0;
|
||||||
convert_crlf(DragData, strlen(DragData));
|
Fl_Screen_Driver::convert_crlf(DragData, strlen(DragData));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Fl_Cocoa_Screen_Driver::breakMacEventLoop();
|
Fl_Cocoa_Screen_Driver::breakMacEventLoop();
|
||||||
@@ -3451,22 +3450,6 @@ Fl_Quartz_Copy_Surface_Driver::~Fl_Quartz_Copy_Surface_Driver()
|
|||||||
// Copy & Paste fltk implementation.
|
// Copy & Paste fltk implementation.
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static size_t convert_crlf(char * s, size_t len)
|
|
||||||
{
|
|
||||||
// turn \r characters into \n and "\r\n" sequences into \n:
|
|
||||||
char *p;
|
|
||||||
size_t l = len;
|
|
||||||
while ((p = strchr(s, '\r'))) {
|
|
||||||
if (*(p+1) == '\n') {
|
|
||||||
memmove(p, p+1, l-(p-s));
|
|
||||||
len--; l--;
|
|
||||||
} else *p = '\n';
|
|
||||||
l -= p-s;
|
|
||||||
s = p + 1;
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// clipboard variables definitions :
|
// clipboard variables definitions :
|
||||||
char *fl_selection_buffer[2] = {NULL, NULL};
|
char *fl_selection_buffer[2] = {NULL, NULL};
|
||||||
int fl_selection_length[2] = {0, 0};
|
int fl_selection_length[2] = {0, 0};
|
||||||
@@ -3547,7 +3530,7 @@ static int get_plain_text_from_clipboard(int clipboard)
|
|||||||
[data getBytes:fl_selection_buffer[clipboard]];
|
[data getBytes:fl_selection_buffer[clipboard]];
|
||||||
}
|
}
|
||||||
fl_selection_buffer[clipboard][len - 1] = 0;
|
fl_selection_buffer[clipboard][len - 1] = 0;
|
||||||
length = convert_crlf(fl_selection_buffer[clipboard], len - 1); // turn all \r characters into \n:
|
length = Fl_Screen_Driver::convert_crlf(fl_selection_buffer[clipboard], len - 1); // turn all \r characters into \n:
|
||||||
Fl::e_clipboard_type = Fl::clipboard_plain_text;
|
Fl::e_clipboard_type = Fl::clipboard_plain_text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -320,32 +320,6 @@ static void data_device_handle_selection(void *data, struct wl_data_device *data
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// turn '\r' characters into '\n' and "\r\n" sequences into '\n'
|
|
||||||
// returns new length
|
|
||||||
static size_t convert_crlf(char *s, size_t len) {
|
|
||||||
char *src = (char *)memchr(s, '\r', len); // find first `\r` in buffer
|
|
||||||
if (src) {
|
|
||||||
char *dst = src;
|
|
||||||
char *end = s + len;
|
|
||||||
while (src < end) {
|
|
||||||
if (*src == '\r') {
|
|
||||||
if (src + 1 < end && *(src + 1) == '\n') {
|
|
||||||
src++; // skip '\r'
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
*dst++ = '\n'; // replace single '\r' with '\n'
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*dst++ = *src;
|
|
||||||
}
|
|
||||||
src++;
|
|
||||||
}
|
|
||||||
return (dst - s);
|
|
||||||
}
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Gets from the system the clipboard or dnd text and puts it in fl_selection_buffer[1]
|
// Gets from the system the clipboard or dnd text and puts it in fl_selection_buffer[1]
|
||||||
// which is enlarged if necessary.
|
// which is enlarged if necessary.
|
||||||
static void get_clipboard_or_dragged_text(struct wl_data_offer *offer) {
|
static void get_clipboard_or_dragged_text(struct wl_data_offer *offer) {
|
||||||
@@ -365,7 +339,7 @@ static void get_clipboard_or_dragged_text(struct wl_data_offer *offer) {
|
|||||||
fl_selection_buffer[1][ fl_selection_length[1] ] = 0;
|
fl_selection_buffer[1][ fl_selection_length[1] ] = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
n = convert_crlf(to, n);
|
n = Fl_Screen_Driver::convert_crlf(to, n);
|
||||||
to += n;
|
to += n;
|
||||||
rest -= n;
|
rest -= n;
|
||||||
}
|
}
|
||||||
@@ -398,7 +372,7 @@ static void get_clipboard_or_dragged_text(struct wl_data_offer *offer) {
|
|||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
n = convert_crlf(from, n);
|
n = Fl_Screen_Driver::convert_crlf(from, n);
|
||||||
from += n;
|
from += n;
|
||||||
}
|
}
|
||||||
fl_selection_length[1] = from - fl_selection_buffer[1];;
|
fl_selection_length[1] = from - fl_selection_buffer[1];;
|
||||||
|
|||||||
Reference in New Issue
Block a user