From 8da644f44279d4e566a77f4227173915ff49a7c6 Mon Sep 17 00:00:00 2001 From: Adrian Lees Date: Thu, 21 Apr 2005 21:36:23 +0000 Subject: [PATCH] [project @ 2005-04-21 21:36:23 by adrianl] Dragging URLs into toolbar URL icon; keyboard actions in textareas conform to Wimp's icon editing; display of scale % fixed for 120% svn path=/import/netsurf/; revision=1676 --- riscos/gui.c | 17 ++++++- riscos/gui.h | 5 ++ riscos/window.c | 123 ++++++++++++++++++++++++++++++++++++++++-------- utils/utils.h | 9 ++++ 4 files changed, 133 insertions(+), 21 deletions(-) diff --git a/riscos/gui.c b/riscos/gui.c index 2e9a92db7..0d35ed78d 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -105,6 +105,8 @@ #endif +int os_version = 0; + const char *__dynamic_da_name = "NetSurf"; /**< For UnixLib. */ int __dynamic_da_max_size = 128 * 1024 * 1024; /**< For UnixLib. */ int __feature_imagefs_is_file = 1; /**< For UnixLib. */ @@ -230,6 +232,10 @@ void gui_init(int argc, char** argv) xhourglass_start(1); + /* read OS version for code that adapts to conform to the OS (remember + that it's preferable to check for specific features being present) */ + xos_byte(osbyte_IN_KEY, 0, 0xff, &os_version, NULL); + atexit(ro_gui_cleanup); signal(SIGABRT, ro_gui_signal); signal(SIGFPE, ro_gui_signal); @@ -1322,8 +1328,15 @@ void ro_msg_dataload(wimp_message *message) bool tree_edit = false; g = ro_gui_window_lookup(message->data.data_xfer.w); - if (g && ro_gui_window_dataload(g, message)) - return; + if (g) { + if (ro_gui_window_dataload(g, message)) + return; + } + else { + g = ro_gui_toolbar_lookup(message->data.data_xfer.w); + if (g && ro_gui_toolbar_dataload(g, message)) + return; + } switch (file_type) { case FILETYPE_ACORN_URI: diff --git a/riscos/gui.h b/riscos/gui.h index 4b4c056c5..6d88a37c7 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -21,6 +21,10 @@ #include "netsurf/desktop/options.h" #include "netsurf/desktop/tree.h" +#define RISCOS5 0xAA + +extern int os_version; + extern const char * NETSURF_DIR; struct toolbar; @@ -162,6 +166,7 @@ int window_x_units(int x, wimp_window_state *state); int window_y_units(int y, wimp_window_state *state); bool window_screen_pos(struct gui_window *g, int x, int y, os_coord *pos); bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message); +bool ro_gui_toolbar_dataload(struct gui_window *g, wimp_message *message); void ro_gui_window_process_reformats(void); void ro_gui_window_default_options(struct browser_window *bw); void ro_gui_window_redraw_all(void); diff --git a/riscos/window.c b/riscos/window.c index 4dda96926..aab46b952 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -7,6 +7,7 @@ * Copyright 2003 John M Bell * Copyright 2004 Andrew Timmins * Copyright 2005 Richard Wilson + * Copyright 2005 Adrian Lees */ /** \file @@ -14,6 +15,7 @@ */ #include +#include #include #include #include @@ -48,6 +50,7 @@ #include "netsurf/utils/log.h" #include "netsurf/utils/talloc.h" #include "netsurf/utils/url.h" +#include "netsurf/utils/utf8.h" #include "netsurf/utils/utils.h" #include "netsurf/utils/messages.h" @@ -66,10 +69,12 @@ static float scale_snap_to[] = {0.10, 0.125, 0.25, 0.333, 0.5, 0.75, 1.5, 2.0, 3.0, 4.0, 6.0, 8.0, 12.0, 16.0}; #define SCALE_SNAP_TO_SIZE (sizeof scale_snap_to) / (sizeof(float)) +static void ro_gui_window_launch_url(struct gui_window *g, const char *url); static void ro_gui_window_clone_options(struct browser_window *new_bw, struct browser_window *old_bw); static browser_mouse_state ro_gui_mouse_drag_state(wimp_mouse_state buttons); -static bool ro_gui_window_import_text(struct gui_window *g, const char *filename); +static bool ro_gui_window_import_text(struct gui_window *g, const char *filename, + bool toolbar); @@ -355,7 +360,7 @@ void gui_window_set_title(struct gui_window *g, const char *title) if (g->option.scale != 1.0) { scale_disp = g->option.scale * 100; - if ((float)scale_disp != g->option.scale * 100) + if (ABS((float)scale_disp - g->option.scale * 100) >= 0.05) snprintf(g->title, sizeof g->title, "%s (%.1f%%)", title, g->option.scale * 100); else @@ -930,6 +935,29 @@ void gui_window_set_url(struct gui_window *g, const char *url) } +/** + * Launch a new url in the given window. + * + * \param g gui_window to update + * \param url url to be launched + */ + +void ro_gui_window_launch_url(struct gui_window *g, const char *url) +{ + url_func_result res; + char *url_norm; + + ro_gui_url_complete_close(NULL, 0); + res = url_normalize(url, &url_norm); + if (res == URL_FUNC_OK) { + gui_window_set_url(g, url_norm); + browser_window_go(g->bw, url_norm, 0); + global_history_add_recent(url_norm); + free(url_norm); + } +} + + /** * Forces all windows to be set to the current theme * @@ -1547,11 +1575,9 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) struct content *content = g->bw->current_content; wimp_window_state state; int y, t_alphabet; - char *url; char *toolbar_url; os_error *error; wimp_pointer pointer; - url_func_result res; float old_scale; static int *ucstable = NULL; static int alphabet = 0; @@ -1631,6 +1657,11 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) /* cursor movement keys */ case wimp_KEY_CONTROL | wimp_KEY_LEFT: c = KEY_LINE_START; break; case wimp_KEY_END: + if (os_version >= RISCOS5) + c = KEY_LINE_END; + else + c = KEY_DELETE_RIGHT; + break; case wimp_KEY_CONTROL | wimp_KEY_RIGHT: c = KEY_LINE_END; break; case wimp_KEY_CONTROL | wimp_KEY_UP: c = KEY_TEXT_START; break; case wimp_KEY_CONTROL | wimp_KEY_DOWN: c = KEY_TEXT_END; break; @@ -1644,7 +1675,15 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) case wimp_KEY_DOWN: c = KEY_DOWN; break; /* editing */ - case wimp_KEY_CONTROL | wimp_KEY_END: c = 136; break; + case wimp_KEY_CONTROL | wimp_KEY_END: + c = KEY_DELETE_LINE_END; + break; + case wimp_KEY_DELETE: + if (ro_gui_ctrl_pressed()) + c = KEY_DELETE_LINE_START; + else if (os_version < RISCOS5) + c = KEY_DELETE_LEFT; + break; } if (c < 256) { @@ -1827,16 +1866,9 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) case wimp_KEY_RETURN: if (!toolbar) break; - ro_gui_url_complete_close(NULL, 0); toolbar_url = ro_gui_get_icon_string(g->toolbar->toolbar_handle, ICON_TOOLBAR_URL); - res = url_normalize(toolbar_url, &url); - if (res == URL_FUNC_OK) { - gui_window_set_url(g, url); - browser_window_go(g->bw, url, 0); - global_history_add_recent(url); - free(url); - } + ro_gui_window_launch_url(g, toolbar_url); return true; case wimp_KEY_ESCAPE: @@ -2130,15 +2162,17 @@ bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message) x + file_box->width, y + file_box->height); } - else { + else if (message->data.data_xfer.file_type == osfile_TYPE_TEXT) { const char *filename = message->data.data_xfer.file_name; browser_window_mouse_click(g->bw, BROWSER_MOUSE_CLICK_1, x, y); - if (!ro_gui_window_import_text(g, filename)) + if (!ro_gui_window_import_text(g, filename, false)) return true; /* it was for us, it just didn't work! */ } + else + return false; /* only text files allowed in textareas/input fields */ /* send DataLoadAck */ message->action = message_DATA_LOAD_ACK; @@ -2154,6 +2188,36 @@ bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message) } +/** + * Handle Message_DataLoad (file dragged in) for a toolbar + * + * \param g window + * \param message Message_DataLoad block + * \return true if the load was processed + */ + +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)) { + + 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); + if (error) { + LOG(("xwimp_send_message: 0x%x: %s\n", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + return true; + } + return false; +} + + /** * Process pending reformats */ @@ -2550,14 +2614,16 @@ void ro_gui_window_set_scale(struct gui_window *g, float scale) /** - * Import text file into textarea at caret position + * Import text file into window or its toolbar * * \param g gui window containing textarea * \param filename pathname of file to be imported + * \param toolbar true iff imported to toolbar rather than main window * \return true iff successful */ -bool ro_gui_window_import_text(struct gui_window *g, const char *filename) +bool ro_gui_window_import_text(struct gui_window *g, const char *filename, + bool toolbar) { fileswitch_object_type obj_type; os_error *error; @@ -2573,7 +2639,7 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename) return true; /* was for us, but it didn't work! */ } - buf = malloc(size); + buf = malloc(size + 1); /* allow room for NUL terminator */ if (!buf) { warn_user("NoMemory", NULL); return true; @@ -2589,7 +2655,26 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename) return true; } - browser_window_paste_text(g->bw, buf, size, true); + if (toolbar) { + const char *ep = buf + size; + const char *sp; + char *p = buf; + + /* skip leading whitespace */ + while (p < ep && isspace(*p)) p++; + + sp = p; + while (p < ep) { + if (*p == '\n' || *p == '\r') break; + 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, buf, size, true); free(buf); return true; diff --git a/utils/utils.h b/utils/utils.h index 278446e0c..e005fcbf7 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -19,6 +19,15 @@ #ifndef NOF_ELEMENTS #define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array))) #endif +#ifndef ABS +#define ABS(x) (((x)>0)?(x):(-(x))) +#endif +#ifndef min +#define min(x,y) (((x)<(y))?(x):(y)) +#endif +#ifndef max +#define max(x,y) (((x)>(y))?(x):(y)) +#endif char * strip(char * const s); int whitespace(const char * str);