2003-10-01 04:26:42 +04:00
|
|
|
/*
|
2005-04-15 09:54:44 +04:00
|
|
|
* Copyright 2005 Adrian Lees <adrianl@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-10-01 04:26:42 +04:00
|
|
|
*/
|
|
|
|
|
2005-04-15 09:54:44 +04:00
|
|
|
/** \file
|
|
|
|
* Text selection code (platform-dependent implementation)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2003-12-27 03:11:57 +03:00
|
|
|
#include <string.h>
|
2016-04-22 00:36:21 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <oslib/osfile.h>
|
|
|
|
#include <oslib/wimp.h>
|
2014-02-01 14:45:20 +04:00
|
|
|
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utf8.h"
|
|
|
|
#include "utils/utils.h"
|
2010-04-07 21:42:21 +04:00
|
|
|
#include "content/hlcache.h"
|
2014-10-16 12:50:55 +04:00
|
|
|
#include "desktop/gui_clipboard.h"
|
|
|
|
#include "desktop/gui_window.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/textinput.h"
|
2014-06-05 18:14:49 +04:00
|
|
|
#include "desktop/browser.h"
|
2014-02-01 14:45:20 +04:00
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/gui.h"
|
2011-02-21 02:16:33 +03:00
|
|
|
#include "riscos/menus.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/message.h"
|
2013-09-08 03:47:55 +04:00
|
|
|
#include "riscos/mouse.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/save.h"
|
|
|
|
#include "riscos/textselection.h"
|
2014-02-02 02:17:36 +04:00
|
|
|
#include "riscos/ucstables.h"
|
2014-02-01 14:45:20 +04:00
|
|
|
|
2003-10-06 03:30:21 +04:00
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
#ifndef wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX
|
|
|
|
#define wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX ((wimp_drag_claim_flags) 0x2u)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/** Receive of Dragging message has claimed it */
|
|
|
|
static bool dragging_claimed = false;
|
|
|
|
static wimp_t dragging_claimant;
|
|
|
|
static os_box dragging_box = { -34, -34, 34, 34 }; /* \todo - size properly */
|
|
|
|
static wimp_drag_claim_flags last_claim_flags = 0;
|
2006-03-10 12:09:03 +03:00
|
|
|
static struct gui_window *last_start_window;
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
static bool drag_claimed = false;
|
2003-10-01 04:26:42 +04:00
|
|
|
|
2005-04-15 09:54:44 +04:00
|
|
|
static bool owns_clipboard = false;
|
|
|
|
static bool owns_caret_and_selection = false;
|
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
/* Current clipboard contents if we own the clipboard
|
|
|
|
* Current paste buffer if we don't
|
|
|
|
*/
|
2005-04-15 09:54:44 +04:00
|
|
|
static char *clipboard = NULL;
|
|
|
|
static size_t clip_length = 0;
|
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
/* Paste context */
|
|
|
|
static ro_gui_selection_prepare_paste_cb paste_cb = NULL;
|
|
|
|
static void *paste_cb_pw = NULL;
|
|
|
|
static int paste_prev_message = 0;
|
|
|
|
|
2013-09-08 03:47:55 +04:00
|
|
|
static void ro_gui_selection_drag_end(wimp_dragged *drag, void *g);
|
2005-04-15 09:54:44 +04:00
|
|
|
static void ro_gui_discard_clipboard_contents(void);
|
2006-02-16 02:09:55 +03:00
|
|
|
static void ro_gui_dragging_bounced(wimp_message *message);
|
2005-04-15 09:54:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start drag-selecting text within a browser window (RO-dependent part)
|
|
|
|
*
|
|
|
|
* \param g gui window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void gui_start_selection(struct gui_window *g)
|
2003-10-01 04:26:42 +04:00
|
|
|
{
|
2005-04-15 09:54:44 +04:00
|
|
|
wimp_full_message_claim_entity msg;
|
|
|
|
wimp_auto_scroll_info scroll;
|
|
|
|
wimp_window_state state;
|
|
|
|
wimp_drag drag;
|
|
|
|
os_error *error;
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("starting text_selection drag");
|
2005-04-15 09:54:44 +04:00
|
|
|
|
|
|
|
state.w = g->window;
|
|
|
|
error = xwimp_get_window_state(&state);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_get_window_state 0x%x: %s", error->errnum, error->errmess);
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("WimpError", error->errmess);
|
2005-04-15 09:54:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* claim caret and selection */
|
|
|
|
msg.size = sizeof(msg);
|
|
|
|
msg.your_ref = 0;
|
|
|
|
msg.action = message_CLAIM_ENTITY;
|
|
|
|
msg.flags = wimp_CLAIM_CARET_OR_SELECTION;
|
|
|
|
|
2006-02-02 20:32:00 +03:00
|
|
|
error = xwimp_send_message(wimp_USER_MESSAGE,
|
|
|
|
(wimp_message*)&msg, wimp_BROADCAST);
|
2005-04-15 09:54:44 +04:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_send_message: 0x%x: %s", error->errnum, error->errmess);
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("WimpError", error->errmess);
|
2005-04-15 09:54:44 +04:00
|
|
|
}
|
|
|
|
owns_caret_and_selection = true;
|
|
|
|
|
|
|
|
scroll.w = g->window;
|
|
|
|
scroll.pause_zone_sizes.x0 = 80;
|
|
|
|
scroll.pause_zone_sizes.y0 = 80;
|
|
|
|
scroll.pause_zone_sizes.x1 = 80;
|
|
|
|
scroll.pause_zone_sizes.y1 = 80;
|
|
|
|
scroll.pause_duration = 0;
|
|
|
|
scroll.state_change = (void *)0;
|
|
|
|
error = xwimp_auto_scroll(wimp_AUTO_SCROLL_ENABLE_VERTICAL |
|
|
|
|
wimp_AUTO_SCROLL_ENABLE_HORIZONTAL,
|
|
|
|
&scroll, 0);
|
|
|
|
if (error)
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_auto_scroll: 0x%x: %s", error->errnum, error->errmess);
|
2004-02-26 03:44:42 +03:00
|
|
|
|
2013-09-08 03:47:55 +04:00
|
|
|
ro_mouse_drag_start(ro_gui_selection_drag_end, ro_gui_window_mouse_at,
|
|
|
|
NULL, g);
|
2004-02-26 03:44:42 +03:00
|
|
|
|
|
|
|
drag.type = wimp_DRAG_USER_POINT;
|
2008-06-04 01:51:25 +04:00
|
|
|
/* Don't constrain mouse pointer during drags */
|
|
|
|
drag.bbox.x0 = -16384;
|
|
|
|
drag.bbox.y0 = -16384;
|
|
|
|
drag.bbox.x1 = 16384;
|
|
|
|
drag.bbox.y1 = 16384;
|
2005-04-15 09:54:44 +04:00
|
|
|
|
|
|
|
error = xwimp_drag_box(&drag);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_drag_box: 0x%x : %s", error->errnum, error->errmess);
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("WimpError", error->errmess);
|
2005-04-15 09:54:44 +04:00
|
|
|
}
|
2006-03-10 12:09:03 +03:00
|
|
|
last_start_window = g;
|
2003-10-01 04:26:42 +04:00
|
|
|
}
|
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
|
2005-04-15 09:54:44 +04:00
|
|
|
/**
|
|
|
|
* End of text selection drag operation
|
|
|
|
*
|
2013-09-08 03:47:55 +04:00
|
|
|
* \param *drag position of pointer at conclusion of drag
|
|
|
|
* \param *data gui window pointer.
|
2005-04-15 09:54:44 +04:00
|
|
|
*/
|
|
|
|
|
2013-09-08 03:47:55 +04:00
|
|
|
static void ro_gui_selection_drag_end(wimp_dragged *drag, void *data)
|
2003-10-01 04:26:42 +04:00
|
|
|
{
|
2005-04-15 09:54:44 +04:00
|
|
|
wimp_auto_scroll_info scroll;
|
|
|
|
wimp_pointer pointer;
|
|
|
|
os_error *error;
|
2006-09-07 02:15:58 +04:00
|
|
|
os_coord pos;
|
2013-09-08 03:47:55 +04:00
|
|
|
struct gui_window *g = (struct gui_window *) data;
|
2005-04-15 09:54:44 +04:00
|
|
|
|
|
|
|
scroll.w = g->window;
|
|
|
|
error = xwimp_auto_scroll(0, &scroll, 0);
|
|
|
|
if (error)
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_auto_scroll: 0x%x: %s", error->errnum, error->errmess);
|
2005-04-15 09:54:44 +04:00
|
|
|
|
|
|
|
error = xwimp_drag_box((wimp_drag*)-1);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_drag_box: 0x%x : %s", error->errnum, error->errmess);
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("WimpError", error->errmess);
|
2005-04-15 09:54:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
error = xwimp_get_pointer_info(&pointer);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_get_pointer_info 0x%x : %s", error->errnum, error->errmess);
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("WimpError", error->errmess);
|
2005-04-15 09:54:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-07 02:15:58 +04:00
|
|
|
if (ro_gui_window_to_window_pos(g, drag->final.x0, drag->final.y0, &pos))
|
2011-06-27 21:45:17 +04:00
|
|
|
browser_window_mouse_track(g->bw, 0, pos.x, pos.y);
|
2003-10-01 04:26:42 +04:00
|
|
|
}
|
|
|
|
|
2005-07-21 03:27:28 +04:00
|
|
|
/**
|
2013-01-08 21:03:50 +04:00
|
|
|
* Core tells front end to put given text in clipboard
|
2005-07-21 03:27:28 +04:00
|
|
|
*
|
2013-01-08 21:03:50 +04:00
|
|
|
* \param buffer UTF-8 text, owned by core
|
|
|
|
* \param length Byte length of UTF-8 text in buffer
|
|
|
|
* \param styles Array of styles given to text runs, owned by core, or NULL
|
|
|
|
* \param n_styles Number of text run styles in array
|
2005-07-21 03:27:28 +04:00
|
|
|
*/
|
2014-02-01 14:45:20 +04:00
|
|
|
static void gui_set_clipboard(const char *buffer, size_t length,
|
2013-01-08 21:03:50 +04:00
|
|
|
nsclipboard_styles styles[], int n_styles)
|
2005-07-21 03:27:28 +04:00
|
|
|
{
|
2013-01-08 21:03:50 +04:00
|
|
|
char *new_cb;
|
2005-04-15 09:54:44 +04:00
|
|
|
|
2013-01-08 21:03:50 +04:00
|
|
|
if (length == 0)
|
|
|
|
return;
|
2003-10-01 04:26:42 +04:00
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
new_cb = malloc(length);
|
|
|
|
if (new_cb == NULL)
|
2013-01-08 21:03:50 +04:00
|
|
|
return;
|
2005-04-15 09:54:44 +04:00
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
memcpy(new_cb, buffer, length);
|
|
|
|
|
|
|
|
/* Replace existing clipboard contents */
|
2013-01-08 21:03:50 +04:00
|
|
|
free(clipboard);
|
|
|
|
clipboard = new_cb;
|
2013-01-22 12:51:58 +04:00
|
|
|
clip_length = length;
|
2005-07-19 08:05:08 +04:00
|
|
|
|
2005-04-15 09:54:44 +04:00
|
|
|
if (!owns_clipboard) {
|
2013-01-08 21:03:50 +04:00
|
|
|
/* Tell RO we now own clipboard */
|
2005-04-15 09:54:44 +04:00
|
|
|
wimp_full_message_claim_entity msg;
|
|
|
|
os_error *error;
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("claiming clipboard");
|
2005-04-15 09:54:44 +04:00
|
|
|
|
|
|
|
msg.size = sizeof(msg);
|
|
|
|
msg.your_ref = 0;
|
|
|
|
msg.action = message_CLAIM_ENTITY;
|
|
|
|
msg.flags = wimp_CLAIM_CLIPBOARD;
|
|
|
|
|
2006-02-02 20:32:00 +03:00
|
|
|
error = xwimp_send_message(wimp_USER_MESSAGE,
|
|
|
|
(wimp_message*)&msg, wimp_BROADCAST);
|
2005-04-15 09:54:44 +04:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_send_message: 0x%x: %s", error->errnum, error->errmess);
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("WimpError", error->errmess);
|
2005-04-15 09:54:44 +04:00
|
|
|
}
|
|
|
|
owns_clipboard = true;
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("clipboard now holds %zd bytes", clip_length);
|
2005-04-15 09:54:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-21 03:27:28 +04:00
|
|
|
/**
|
2013-01-08 21:03:50 +04:00
|
|
|
* Core asks front end for clipboard contents.
|
2005-07-21 03:27:28 +04:00
|
|
|
*
|
2013-01-22 12:51:58 +04:00
|
|
|
* \param buffer UTF-8 text, allocated by front end, ownership yielded to core
|
2013-01-08 21:03:50 +04:00
|
|
|
* \param length Byte length of UTF-8 text in buffer
|
2005-07-21 03:27:28 +04:00
|
|
|
*/
|
2014-02-01 14:45:20 +04:00
|
|
|
static void gui_get_clipboard(char **buffer, size_t *length)
|
2005-07-21 03:27:28 +04:00
|
|
|
{
|
2013-01-08 21:03:50 +04:00
|
|
|
*buffer = NULL;
|
|
|
|
*length = 0;
|
2005-07-21 03:27:28 +04:00
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
if (clip_length > 0) {
|
|
|
|
char *cb = malloc(clip_length);
|
|
|
|
if (cb != NULL) {
|
|
|
|
memcpy(cb, clipboard, clip_length);
|
|
|
|
*buffer = cb;
|
|
|
|
*length = clip_length;
|
2006-02-02 20:32:00 +03:00
|
|
|
}
|
2013-01-22 12:51:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 21:03:50 +04:00
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
/**
|
|
|
|
* Discard the current contents of the clipboard, if any, releasing the
|
|
|
|
* memory it uses.
|
2013-01-08 21:03:50 +04:00
|
|
|
*/
|
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
void ro_gui_discard_clipboard_contents(void)
|
|
|
|
{
|
|
|
|
free(clipboard);
|
2013-02-14 03:46:06 +04:00
|
|
|
clipboard = NULL;
|
2013-01-22 12:51:58 +04:00
|
|
|
clip_length = 0;
|
|
|
|
}
|
|
|
|
|
2005-04-20 16:24:41 +04:00
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
static void ro_gui_selection_prepare_paste_complete(void)
|
|
|
|
{
|
|
|
|
ro_gui_selection_prepare_paste_cb cb = paste_cb;
|
|
|
|
void *pw = paste_cb_pw;
|
|
|
|
|
|
|
|
paste_cb = NULL;
|
|
|
|
paste_cb_pw = NULL;
|
|
|
|
paste_prev_message = 0;
|
|
|
|
|
|
|
|
cb(pw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ro_gui_selection_prepare_paste_bounced(wimp_message *message)
|
|
|
|
{
|
|
|
|
ro_gui_selection_prepare_paste_complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare to paste data from another application
|
|
|
|
*
|
|
|
|
* \param w Window being pasted into
|
|
|
|
* \param cb Callback to call once preparation is complete
|
|
|
|
* \param pw Private data for callback
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_selection_prepare_paste(wimp_w w,
|
|
|
|
ro_gui_selection_prepare_paste_cb cb, void *pw)
|
|
|
|
{
|
|
|
|
if (owns_clipboard) {
|
|
|
|
/* We own the clipboard: we're already prepared */
|
|
|
|
cb(pw);
|
|
|
|
} else {
|
|
|
|
/* Someone else owns the clipboard: request its contents */
|
|
|
|
wimp_full_message_data_request msg;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
ro_gui_discard_clipboard_contents();
|
2005-04-20 16:24:41 +04:00
|
|
|
|
2013-02-25 03:58:02 +04:00
|
|
|
msg.size = 48; /* There's only one filetype listed. */
|
2005-04-20 16:24:41 +04:00
|
|
|
msg.your_ref = 0;
|
|
|
|
msg.action = message_DATA_REQUEST;
|
2013-01-22 12:51:58 +04:00
|
|
|
msg.w = w;
|
2005-04-20 16:24:41 +04:00
|
|
|
msg.i = -1;
|
2013-01-22 12:51:58 +04:00
|
|
|
msg.pos.x = 0;
|
|
|
|
msg.pos.y = 0;
|
2005-04-20 16:24:41 +04:00
|
|
|
msg.flags = wimp_DATA_REQUEST_CLIPBOARD;
|
|
|
|
msg.file_types[0] = osfile_TYPE_TEXT;
|
|
|
|
msg.file_types[1] = ~0;
|
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
success = ro_message_send_message(wimp_USER_MESSAGE_RECORDED,
|
|
|
|
(wimp_message *) &msg, wimp_BROADCAST,
|
|
|
|
ro_gui_selection_prepare_paste_bounced);
|
|
|
|
if (success == false) {
|
|
|
|
/* Ensure key is handled, anyway */
|
|
|
|
cb(pw);
|
|
|
|
} else {
|
|
|
|
/* Set up paste context */
|
|
|
|
paste_cb = cb;
|
|
|
|
paste_cb_pw = pw;
|
|
|
|
paste_prev_message = msg.my_ref;
|
2005-04-20 16:24:41 +04:00
|
|
|
}
|
2013-01-22 12:51:58 +04:00
|
|
|
}
|
2005-04-20 16:24:41 +04:00
|
|
|
}
|
|
|
|
|
2005-04-15 09:54:44 +04:00
|
|
|
/**
|
2013-01-22 12:51:58 +04:00
|
|
|
* Prepare to paste data from another application (step 2)
|
|
|
|
*
|
|
|
|
* \param dataxfer DataSave message
|
|
|
|
* \return True if message was handled, false otherwise
|
2005-04-15 09:54:44 +04:00
|
|
|
*/
|
2013-01-22 12:51:58 +04:00
|
|
|
bool ro_gui_selection_prepare_paste_datasave(
|
|
|
|
wimp_full_message_data_xfer *dataxfer)
|
|
|
|
{
|
|
|
|
bool success;
|
2005-04-15 09:54:44 +04:00
|
|
|
|
2013-01-22 12:51:58 +04:00
|
|
|
/* Ignore messages that aren't for us */
|
|
|
|
if (dataxfer->your_ref == 0 || dataxfer->your_ref != paste_prev_message)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* We're done if the paste data isn't text */
|
|
|
|
if (dataxfer->file_type != osfile_TYPE_TEXT) {
|
|
|
|
ro_gui_selection_prepare_paste_complete();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate and send DataSaveAck */
|
|
|
|
dataxfer->your_ref = dataxfer->my_ref;
|
|
|
|
dataxfer->size = offsetof(wimp_full_message_data_xfer, file_name) + 16;
|
|
|
|
dataxfer->action = message_DATA_SAVE_ACK;
|
|
|
|
dataxfer->est_size = -1;
|
|
|
|
memcpy(dataxfer->file_name, "<Wimp$Scrap>", SLEN("<Wimp$Scrap>") + 1);
|
|
|
|
|
|
|
|
success = ro_message_send_message(wimp_USER_MESSAGE_RECORDED,
|
|
|
|
(wimp_message *) dataxfer, dataxfer->sender,
|
|
|
|
ro_gui_selection_prepare_paste_bounced);
|
|
|
|
if (success == false) {
|
|
|
|
ro_gui_selection_prepare_paste_complete();
|
|
|
|
} else {
|
|
|
|
paste_prev_message = dataxfer->my_ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare to paste data from another application (step 3)
|
|
|
|
*
|
|
|
|
* \param dataxfer DataLoad message
|
|
|
|
* \return True if message was handled, false otherwise
|
|
|
|
*/
|
|
|
|
bool ro_gui_selection_prepare_paste_dataload(
|
|
|
|
wimp_full_message_data_xfer *dataxfer)
|
2005-04-15 09:54:44 +04:00
|
|
|
{
|
2013-01-22 12:51:58 +04:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
/* Ignore messages that aren't for us */
|
|
|
|
if (dataxfer->your_ref == 0 || dataxfer->your_ref != paste_prev_message)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fp = fopen(dataxfer->file_name, "r");
|
|
|
|
if (fp != NULL) {
|
2014-05-31 02:02:02 +04:00
|
|
|
long size;
|
2013-01-22 12:51:58 +04:00
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
size = ftell(fp);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
|
2013-02-14 03:46:06 +04:00
|
|
|
if (size > 0) {
|
2014-05-31 02:02:02 +04:00
|
|
|
char *local_cb = malloc(size);
|
2013-02-14 03:46:06 +04:00
|
|
|
if (local_cb != NULL) {
|
2014-05-31 02:02:02 +04:00
|
|
|
nserror ret;
|
2013-02-14 03:46:06 +04:00
|
|
|
fread(local_cb, 1, size, fp);
|
2013-01-22 12:51:58 +04:00
|
|
|
|
2013-02-14 03:46:06 +04:00
|
|
|
ret = utf8_from_local_encoding(local_cb, size,
|
|
|
|
&clipboard);
|
2014-01-29 01:40:13 +04:00
|
|
|
if (ret == NSERROR_OK) {
|
2013-02-14 03:46:06 +04:00
|
|
|
clip_length = strlen(clipboard);
|
|
|
|
}
|
2013-02-25 02:59:16 +04:00
|
|
|
|
|
|
|
free(local_cb);
|
2013-01-22 12:51:58 +04:00
|
|
|
}
|
|
|
|
}
|
2013-02-14 03:46:06 +04:00
|
|
|
|
|
|
|
fclose(fp);
|
2013-01-22 12:51:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send DataLoadAck */
|
|
|
|
dataxfer->action = message_DATA_LOAD_ACK;
|
|
|
|
dataxfer->your_ref = dataxfer->my_ref;
|
|
|
|
ro_message_send_message(wimp_USER_MESSAGE,
|
|
|
|
(wimp_message *) dataxfer, dataxfer->sender, NULL);
|
|
|
|
|
|
|
|
ro_gui_selection_prepare_paste_complete();
|
|
|
|
return true;
|
2005-04-15 09:54:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responds to CLAIM_ENTITY message notifying us that the caret
|
|
|
|
* and selection or clipboard have been claimed by another application.
|
|
|
|
*
|
|
|
|
* \param claim CLAIM_ENTITY message
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_selection_claim_entity(wimp_full_message_claim_entity *claim)
|
|
|
|
{
|
|
|
|
/* ignore our own broadcasts! */
|
|
|
|
if (claim->sender != task_handle) {
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("%x", claim->flags);
|
2005-04-15 09:54:44 +04:00
|
|
|
|
|
|
|
if (claim->flags & wimp_CLAIM_CARET_OR_SELECTION) {
|
|
|
|
owns_caret_and_selection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (claim->flags & wimp_CLAIM_CLIPBOARD) {
|
|
|
|
ro_gui_discard_clipboard_contents();
|
|
|
|
owns_clipboard = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responds to DATA_REQUEST message, returning information about the
|
|
|
|
* clipboard contents if we own the clipboard.
|
|
|
|
*
|
|
|
|
* \param req DATA_REQUEST message
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_selection_data_request(wimp_full_message_data_request *req)
|
|
|
|
{
|
|
|
|
if (owns_clipboard && clip_length > 0 &&
|
|
|
|
(req->flags & wimp_DATA_REQUEST_CLIPBOARD)) {
|
|
|
|
wimp_full_message_data_xfer message;
|
|
|
|
int size;
|
|
|
|
// int i;
|
|
|
|
|
|
|
|
// for(i = 0; i < NOF_ELEMENTS(req->file_types); i++) {
|
|
|
|
// bits ftype = req->file_types[i];
|
|
|
|
// if (ftype == ~0U) break; /* list terminator */
|
|
|
|
//
|
2015-05-28 19:06:18 +03:00
|
|
|
// LOG("type %x", ftype);
|
2005-04-15 09:54:44 +04:00
|
|
|
// i++;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/* we can only supply text at the moment, so that's what you're getting! */
|
|
|
|
size = offsetof(wimp_full_message_data_xfer, file_name) + 9;
|
|
|
|
message.size = (size + 3) & ~3;
|
|
|
|
message.your_ref = req->my_ref;
|
|
|
|
message.action = message_DATA_SAVE;
|
|
|
|
message.w = req->w;
|
|
|
|
message.i = req->i;
|
|
|
|
message.pos = req->pos;
|
|
|
|
message.file_type = osfile_TYPE_TEXT;
|
|
|
|
message.est_size = clip_length;
|
|
|
|
memcpy(message.file_name, "TextFile", 9);
|
|
|
|
|
2006-02-02 20:32:00 +03:00
|
|
|
ro_gui_send_datasave(GUI_SAVE_CLIPBOARD_CONTENTS,
|
|
|
|
&message, req->sender);
|
2005-04-15 09:54:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the clipboard contents to a file.
|
|
|
|
*
|
|
|
|
* \param path the pathname of the file
|
|
|
|
* \return true iff success, otherwise reporting the error before returning false
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ro_gui_save_clipboard(const char *path)
|
|
|
|
{
|
2013-01-22 12:51:58 +04:00
|
|
|
char *local_cb;
|
2014-01-29 01:40:13 +04:00
|
|
|
nserror ret;
|
2005-04-15 09:54:44 +04:00
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
assert(clip_length > 0 && clipboard);
|
2013-01-22 12:51:58 +04:00
|
|
|
|
|
|
|
ret = utf8_to_local_encoding(clipboard, clip_length, &local_cb);
|
2014-01-29 01:40:13 +04:00
|
|
|
if (ret != NSERROR_OK) {
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("SaveError", "Could not convert");
|
2013-01-22 12:51:58 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-04-15 09:54:44 +04:00
|
|
|
error = xosfile_save_stamped(path, osfile_TYPE_TEXT,
|
2013-01-22 12:51:58 +04:00
|
|
|
(byte*) local_cb,
|
|
|
|
(byte*) local_cb + strlen(local_cb));
|
|
|
|
|
|
|
|
free(local_cb);
|
|
|
|
|
2005-04-15 09:54:44 +04:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosfile_save_stamped: 0x%x: %s", error->errnum, error->errmess);
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("SaveError", error->errmess);
|
2005-04-15 09:54:44 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-22 12:51:58 +04:00
|
|
|
|
2005-04-15 09:54:44 +04:00
|
|
|
return true;
|
|
|
|
}
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for Message_Dragging, used to implement auto-scrolling and
|
|
|
|
* ghost caret when a drag is in progress.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_selection_dragging(wimp_message *message)
|
|
|
|
{
|
|
|
|
wimp_full_message_dragging *drag = (wimp_full_message_dragging*)message;
|
|
|
|
struct gui_window *g;
|
2006-09-07 02:15:58 +04:00
|
|
|
os_coord pos;
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* with autoscrolling, we will probably need to remember the
|
|
|
|
* gui_window and override the drag->w window handle which
|
2009-05-30 03:12:18 +04:00
|
|
|
* could be any window on the desktop */
|
2006-02-16 02:09:55 +03:00
|
|
|
g = ro_gui_window_lookup(drag->w);
|
|
|
|
|
|
|
|
if ((drag->flags & wimp_DRAGGING_TERMINATE_DRAG) || !g) {
|
|
|
|
|
|
|
|
drag_claimed = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-07 02:15:58 +04:00
|
|
|
if (!ro_gui_window_to_window_pos(g, drag->pos.x, drag->pos.y, &pos))
|
2006-02-16 02:09:55 +03:00
|
|
|
return;
|
|
|
|
|
2012-08-02 18:03:12 +04:00
|
|
|
drag_claimed = false;
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset drag-and-drop state when drag completes (DataSave received)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_selection_drag_reset(void)
|
|
|
|
{
|
|
|
|
drag_claimed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_selection_drag_claim(wimp_message *message)
|
|
|
|
{
|
|
|
|
wimp_full_message_drag_claim *claim = (wimp_full_message_drag_claim*)message;
|
|
|
|
|
|
|
|
dragging_claimant = message->sender;
|
|
|
|
dragging_claimed = true;
|
|
|
|
|
|
|
|
/* have we been asked to remove the drag box/sprite? */
|
|
|
|
if (claim->flags & wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX) {
|
|
|
|
ro_gui_drag_box_cancel();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* \todo - restore it here? */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do we need to restore the default pointer shape? */
|
|
|
|
if ((last_claim_flags & wimp_DRAG_CLAIM_POINTER_CHANGED) &&
|
|
|
|
!(claim->flags & wimp_DRAG_CLAIM_POINTER_CHANGED)) {
|
2006-03-10 12:09:03 +03:00
|
|
|
gui_window_set_pointer(last_start_window, GUI_POINTER_DEFAULT);
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
last_claim_flags = claim->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ro_gui_selection_send_dragging(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
wimp_full_message_dragging dragmsg;
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("sending DRAGGING to %p, %d", pointer->w, pointer->i);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
dragmsg.size = offsetof(wimp_full_message_dragging, file_types) + 8;
|
|
|
|
dragmsg.your_ref = 0;
|
|
|
|
dragmsg.action = message_DRAGGING;
|
|
|
|
dragmsg.w = pointer->w;
|
|
|
|
dragmsg.i = pointer->i;
|
|
|
|
dragmsg.pos = pointer->pos;
|
|
|
|
/* \todo - this is interesting because it depends upon not just the state of the
|
|
|
|
shift key, but also whether it /can/ be deleted, ie. from text area/input
|
|
|
|
rather than page contents */
|
|
|
|
dragmsg.flags = wimp_DRAGGING_FROM_SELECTION;
|
|
|
|
dragmsg.box = dragging_box;
|
|
|
|
dragmsg.file_types[0] = osfile_TYPE_TEXT;
|
|
|
|
dragmsg.file_types[1] = ~0;
|
|
|
|
|
|
|
|
/* if the message_dragmsg messages have been claimed we must address them
|
|
|
|
to the claimant task, which is not necessarily the task that owns whatever
|
|
|
|
window happens to be under the pointer */
|
|
|
|
|
|
|
|
if (dragging_claimed) {
|
|
|
|
ro_message_send_message(wimp_USER_MESSAGE_RECORDED,
|
|
|
|
(wimp_message*)&dragmsg, dragging_claimant, ro_gui_dragging_bounced);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ro_message_send_message_to_window(wimp_USER_MESSAGE_RECORDED,
|
|
|
|
(wimp_message*)&dragmsg, pointer->w, pointer->i,
|
|
|
|
ro_gui_dragging_bounced, &dragging_claimant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Our message_DRAGGING message was bounced, ie. the intended recipient does not
|
|
|
|
* support the drag-and-drop protocol or cannot receive the data at the pointer
|
|
|
|
* position.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_dragging_bounced(wimp_message *message)
|
|
|
|
{
|
|
|
|
dragging_claimed = false;
|
|
|
|
}
|
2014-02-01 14:45:20 +04:00
|
|
|
|
|
|
|
static struct gui_clipboard_table clipboard_table = {
|
|
|
|
.get = gui_get_clipboard,
|
|
|
|
.set = gui_set_clipboard,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gui_clipboard_table *riscos_clipboard_table = &clipboard_table;
|