summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-02-22 12:19:35 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-02-22 12:19:35 +0000
commitc2a718075ad321a9cf4678e72645acda5c3471a9 (patch)
treea634c4c47c579aab35839ee3861ef90f92d89b48 /riscos
parent2b0cc398bb5b8e5dc90fcc0a71a9a154dd9f2d74 (diff)
downloadnetsurf-c2a718075ad321a9cf4678e72645acda5c3471a9.tar.gz
netsurf-c2a718075ad321a9cf4678e72645acda5c3471a9.tar.bz2
A load of refactoring of how content selection and input work.
Keypresses now go via content interface. Contents don't shove the selection object into browser windows any more. Contents report selection existence by sending message. HTML content keeps track of where selections in it exist. Contents report whether they have input focus via caret setting msg. Caret can be hidden (can still input/paste) or removed. Consolidate textarea selection handling. Make textarea report its selection status changes to client. Various textarea fixes. Changed how we decide when to clear selections, and give focus.
Diffstat (limited to 'riscos')
-rw-r--r--riscos/save.c22
-rw-r--r--riscos/save.h2
-rw-r--r--riscos/window.c56
3 files changed, 46 insertions, 34 deletions
diff --git a/riscos/save.c b/riscos/save.c
index 12af6ab22..549a2ab3e 100644
--- a/riscos/save.c
+++ b/riscos/save.c
@@ -79,7 +79,7 @@
static gui_save_type gui_save_current_type;
static hlcache_handle *gui_save_content = NULL;
-static struct selection *gui_save_selection = NULL;
+static char *gui_save_selection = NULL;
static const char *gui_save_url = NULL;
static const char *gui_save_title = NULL;
static int gui_save_filetype;
@@ -246,7 +246,7 @@ void ro_gui_saveas_quit(void)
*/
void ro_gui_save_prepare(gui_save_type save_type, hlcache_handle *h,
- struct selection *s, const char *url, const char *title)
+ char *s, const char *url, const char *title)
{
char name_buf[FILENAME_MAX];
size_t leaf_offset = 0;
@@ -259,6 +259,9 @@ void ro_gui_save_prepare(gui_save_type save_type, hlcache_handle *h,
(save_type == GUI_SAVE_HISTORY_EXPORT_HTML) ||
(save_type == GUI_SAVE_TEXT_SELECTION) || h);
+ if (gui_save_selection == NULL)
+ free(gui_save_selection);
+
gui_save_selection = s;
gui_save_url = url;
gui_save_title = title;
@@ -414,7 +417,11 @@ void gui_drag_save_selection(struct selection *s, struct gui_window *g)
return;
}
- gui_save_selection = s;
+
+ if (gui_save_selection == NULL)
+ free(gui_save_selection);
+
+ gui_save_selection = selection_get_copy(s);
ro_gui_save_set_state(NULL, GUI_SAVE_TEXT_SELECTION, NULL,
save_leafname, LEAFNAME_MAX,
@@ -890,8 +897,15 @@ bool ro_gui_save_content(hlcache_handle *h, char *path, bool force_overwrite)
break;
case GUI_SAVE_TEXT_SELECTION:
- if (!selection_save_text(gui_save_selection, path))
+ if (gui_save_selection == NULL)
+ return false;
+ if (!utf8_save_text(gui_save_selection, path)) {
+ free(gui_save_selection);
+ gui_save_selection = NULL;
return false;
+ }
+ free(gui_save_selection);
+ gui_save_selection = NULL;
xosfile_set_type(path, 0xfff);
break;
diff --git a/riscos/save.h b/riscos/save.h
index c9a0f13e8..b219de4c8 100644
--- a/riscos/save.h
+++ b/riscos/save.h
@@ -30,7 +30,7 @@
wimp_w ro_gui_saveas_create(const char *template_name);
void ro_gui_saveas_quit(void);
void ro_gui_save_prepare(gui_save_type save_type, struct hlcache_handle *h,
- struct selection *s, const char *url,
+ char *s, const char *url,
const char *title);
void ro_gui_save_start_drag(wimp_pointer *pointer);
void ro_gui_drag_save_link(gui_save_type save_type, const char *url,
diff --git a/riscos/window.c b/riscos/window.c
index d82e855ac..0183dbb54 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -145,7 +145,7 @@ static void ro_gui_window_save_toolbar_buttons(void *data, char *config);
static void ro_gui_window_update_theme(void *data, bool ok);
static bool ro_gui_window_import_text(struct gui_window *g,
- const char *filename, bool toolbar);
+ const char *filename);
static void ro_gui_window_clone_options(struct browser_window *new_bw,
struct browser_window *old_bw);
@@ -2167,11 +2167,13 @@ bool ro_gui_window_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
hlcache_handle *h = NULL;
bool export_sprite, export_draw;
os_coord pos;
+ browser_editor_flags editor_flags;
g = (struct gui_window *) ro_gui_wimp_event_get_user_data(w);
toolbar = g->toolbar;
bw = g->bw;
h = g->bw->current_content;
+ editor_flags = browser_window_get_editor_flags(bw);
/* If this is the form select menu, handle it now and then exit.
* Otherwise, carry on to the main browser window menu.
@@ -2327,20 +2329,19 @@ bool ro_gui_window_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
* be selected */
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_SAVE,
- !browser_window_has_selection(bw));
+ editor_flags & ~BW_EDITOR_CAN_COPY);
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_COPY,
- !browser_window_has_selection(bw));
+ editor_flags & ~BW_EDITOR_CAN_COPY);
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_CUT,
- !browser_window_has_selection(bw) ||
- selection_read_only(browser_window_get_selection(bw)));
+ editor_flags & ~BW_EDITOR_CAN_CUT);
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_PASTE,
- h == NULL || bw->paste_callback == NULL);
+ editor_flags & ~BW_EDITOR_CAN_PASTE);
ro_gui_menu_set_entry_shaded(menu, BROWSER_SELECTION_CLEAR,
- !browser_window_has_selection(bw));
+ editor_flags & ~BW_EDITOR_CAN_COPY);
/* Navigate Submenu */
@@ -2477,7 +2478,7 @@ void ro_gui_window_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
break;
case BROWSER_SELECTION_SAVE:
- if (browser_window_has_selection(bw))
+ if (browser_window_get_editor_flags(bw) & BW_EDITOR_CAN_COPY)
ro_gui_save_prepare(GUI_SAVE_TEXT_SELECTION, NULL,
browser_window_get_selection(bw),
NULL, NULL);
@@ -3722,14 +3723,15 @@ void ro_gui_window_toolbar_click(void *data,
bool ro_gui_toolbar_dataload(struct gui_window *g, wimp_message *message)
{
if (message->data.data_xfer.file_type == osfile_TYPE_TEXT &&
- ro_gui_window_import_text(g, message->data.data_xfer.file_name, true)) {
-
+ ro_gui_window_import_text(g,
+ message->data.data_xfer.file_name)) {
os_error *error;
/* send DataLoadAck */
message->action = message_DATA_LOAD_ACK;
message->your_ref = message->my_ref;
- error = xwimp_send_message(wimp_USER_MESSAGE, message, message->sender);
+ error = xwimp_send_message(wimp_USER_MESSAGE, message,
+ message->sender);
if (error) {
LOG(("xwimp_send_message: 0x%x: %s\n",
error->errnum, error->errmess));
@@ -4546,14 +4548,15 @@ void ro_gui_window_update_theme(void *data, bool ok)
* \return true iff successful
*/
-bool ro_gui_window_import_text(struct gui_window *g, const char *filename,
- bool toolbar)
+bool ro_gui_window_import_text(struct gui_window *g, const char *filename)
{
fileswitch_object_type obj_type;
os_error *error;
- char *buf, *utf8_buf;
+ char *buf, *utf8_buf, *sp;
int size;
utf8_convert_ret ret;
+ const char *ep;
+ char *p;
error = xosfile_read_stamped(filename, &obj_type, NULL, NULL,
&size, NULL, NULL);
@@ -4596,24 +4599,19 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename,
}
size = strlen(utf8_buf);
- if (toolbar) {
- const char *ep = utf8_buf + size;
- const char *sp;
- char *p = utf8_buf;
+ ep = utf8_buf + size;
+ p = utf8_buf;
- /* skip leading whitespace */
- while (isspace(*p)) p++;
+ /* skip leading whitespace */
+ while (isspace(*p)) p++;
- sp = p;
- while (*p && *p != '\r' && *p != '\n')
- p += utf8_next(p, ep - p, 0);
- *p = '\0';
+ sp = p;
+ while (*p && *p != '\r' && *p != '\n')
+ p += utf8_next(p, ep - p, 0);
+ *p = '\0';
- if (p > sp)
- ro_gui_window_launch_url(g, sp);
- }
- else
- browser_window_paste_text(g->bw, utf8_buf, size, true);
+ if (p > sp)
+ ro_gui_window_launch_url(g, sp);
free(buf);
free(utf8_buf);