2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2004-02-13 19:09:12 +03:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2003-06-30 16:44:03 +04:00
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
2002-09-11 18:24:02 +04:00
|
|
|
*/
|
|
|
|
|
2003-07-15 18:37:34 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
2003-08-27 02:37:32 +04:00
|
|
|
#include <stddef.h>
|
2003-07-15 18:37:34 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2003-11-08 02:51:13 +03:00
|
|
|
#include <unixlib/local.h>
|
2004-01-28 21:37:56 +03:00
|
|
|
#include "oslib/hourglass.h"
|
2003-12-27 07:50:02 +03:00
|
|
|
#include "oslib/inetsuite.h"
|
2003-01-11 20:33:31 +03:00
|
|
|
#include "oslib/os.h"
|
2004-02-27 17:09:15 +03:00
|
|
|
#include "oslib/osbyte.h"
|
2003-07-15 18:37:34 +04:00
|
|
|
#include "oslib/osfile.h"
|
2004-03-03 03:19:47 +03:00
|
|
|
#include "oslib/osfscontrol.h"
|
2003-08-25 02:39:55 +04:00
|
|
|
#include "oslib/plugin.h"
|
2002-09-11 18:24:02 +04:00
|
|
|
#include "oslib/wimp.h"
|
2003-07-30 17:06:22 +04:00
|
|
|
#include "oslib/uri.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2003-07-15 18:37:34 +04:00
|
|
|
#include "netsurf/desktop/gui.h"
|
|
|
|
#include "netsurf/desktop/netsurf.h"
|
|
|
|
#include "netsurf/desktop/options.h"
|
2003-07-18 03:01:02 +04:00
|
|
|
#include "netsurf/render/font.h"
|
2003-10-25 04:35:49 +04:00
|
|
|
#include "netsurf/render/form.h"
|
2003-07-15 18:37:34 +04:00
|
|
|
#include "netsurf/render/html.h"
|
2003-12-27 01:12:39 +03:00
|
|
|
#include "netsurf/riscos/constdata.h"
|
2003-07-30 17:06:22 +04:00
|
|
|
#include "netsurf/riscos/gui.h"
|
2004-02-13 19:09:12 +03:00
|
|
|
#include "netsurf/riscos/options.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PLUGIN
|
2003-08-25 02:39:55 +04:00
|
|
|
#include "netsurf/riscos/plugin.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2002-10-15 14:41:12 +04:00
|
|
|
#include "netsurf/riscos/theme.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_URI
|
2003-07-30 17:06:22 +04:00
|
|
|
#include "netsurf/riscos/uri.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_URL
|
2004-03-02 21:02:41 +03:00
|
|
|
#include "netsurf/riscos/url_protocol.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-01-11 20:33:31 +03:00
|
|
|
#include "netsurf/utils/log.h"
|
2003-10-01 04:26:42 +04:00
|
|
|
#include "netsurf/utils/messages.h"
|
2003-07-15 18:37:34 +04:00
|
|
|
#include "netsurf/utils/utils.h"
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2003-04-12 01:06:51 +04:00
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
const char *__dynamic_da_name = "NetSurf"; /**< For UnixLib. */
|
2003-06-25 03:22:00 +04:00
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
char *NETSURF_DIR;
|
|
|
|
wimp_menu *combo_menu;
|
|
|
|
struct form_control *current_gadget;
|
|
|
|
gui_window *over_window = 0; /**< Window which the pointer is over. */
|
|
|
|
bool gui_reformat_pending = false; /**< Some windows have been resized,
|
|
|
|
and should be reformatted. */
|
2004-02-26 03:44:42 +03:00
|
|
|
gui_drag_type gui_current_drag_type;
|
2003-11-08 02:51:13 +03:00
|
|
|
static wimp_t task_handle; /**< RISC OS wimp task handle. */
|
|
|
|
/** Accepted wimp user messages. */
|
2004-02-26 03:44:42 +03:00
|
|
|
static const wimp_MESSAGE_LIST(26) task_messages = { {
|
2003-11-08 02:51:13 +03:00
|
|
|
message_DATA_SAVE,
|
|
|
|
message_DATA_SAVE_ACK,
|
|
|
|
message_DATA_LOAD,
|
|
|
|
message_DATA_OPEN,
|
2004-02-26 03:44:42 +03:00
|
|
|
message_MENU_WARNING,
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_URI
|
2003-11-08 02:51:13 +03:00
|
|
|
message_URI_PROCESS,
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_URL
|
2003-12-27 07:50:02 +03:00
|
|
|
message_INET_SUITE_OPEN_URL,
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
2003-11-08 02:51:13 +03:00
|
|
|
message_PLUG_IN_OPENING,
|
|
|
|
message_PLUG_IN_CLOSED,
|
|
|
|
message_PLUG_IN_RESHAPE_REQUEST,
|
|
|
|
message_PLUG_IN_FOCUS,
|
|
|
|
message_PLUG_IN_URL_ACCESS,
|
|
|
|
message_PLUG_IN_STATUS,
|
|
|
|
message_PLUG_IN_BUSY,
|
|
|
|
message_PLUG_IN_STREAM_NEW,
|
|
|
|
message_PLUG_IN_STREAM_WRITE,
|
|
|
|
message_PLUG_IN_STREAM_WRITTEN,
|
|
|
|
message_PLUG_IN_STREAM_DESTROY,
|
|
|
|
message_PLUG_IN_OPEN,
|
|
|
|
message_PLUG_IN_CLOSE,
|
|
|
|
message_PLUG_IN_RESHAPE,
|
|
|
|
message_PLUG_IN_STREAM_AS_FILE,
|
|
|
|
message_PLUG_IN_NOTIFY,
|
|
|
|
message_PLUG_IN_ABORT,
|
|
|
|
message_PLUG_IN_ACTION,
|
|
|
|
/* message_PLUG_IN_INFORMED, (not provided by oslib) */
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-11-08 02:51:13 +03:00
|
|
|
0
|
|
|
|
} };
|
|
|
|
struct ro_gui_poll_block {
|
|
|
|
wimp_event_no event;
|
|
|
|
wimp_block *block;
|
|
|
|
struct ro_gui_poll_block *next;
|
|
|
|
};
|
|
|
|
struct ro_gui_poll_block *ro_gui_poll_queued_blocks = 0;
|
2002-10-15 14:41:12 +04:00
|
|
|
|
2003-07-18 03:01:02 +04:00
|
|
|
|
2004-02-27 17:09:15 +03:00
|
|
|
static void ro_gui_choose_language(void);
|
2003-11-08 02:51:13 +03:00
|
|
|
static void ro_gui_icon_bar_create(void);
|
2004-01-28 21:37:56 +03:00
|
|
|
static void ro_gui_handle_event(wimp_event_no event, wimp_block *block);
|
2003-03-04 14:59:36 +03:00
|
|
|
static void ro_gui_poll_queue(wimp_event_no event, wimp_block* block);
|
2004-01-28 21:37:56 +03:00
|
|
|
static void ro_gui_null_reason_code(void);
|
|
|
|
static void ro_gui_redraw_window_request(wimp_draw *redraw);
|
|
|
|
static void ro_gui_open_window_request(wimp_open *open);
|
|
|
|
static void ro_gui_close_window_request(wimp_close *close);
|
|
|
|
static void ro_gui_mouse_click(wimp_pointer *pointer);
|
2003-11-08 02:51:13 +03:00
|
|
|
static void ro_gui_icon_bar_click(wimp_pointer* pointer);
|
2004-02-26 03:44:42 +03:00
|
|
|
static void ro_gui_drag_end(wimp_dragged *drag);
|
2003-03-04 14:59:36 +03:00
|
|
|
static void ro_gui_keypress(wimp_key* key);
|
2004-01-28 21:37:56 +03:00
|
|
|
static void ro_gui_user_message(wimp_event_no event, wimp_message *message);
|
2003-03-04 14:59:36 +03:00
|
|
|
static void ro_msg_datasave(wimp_message* block);
|
|
|
|
static void ro_msg_dataload(wimp_message* block);
|
2003-10-06 03:30:21 +04:00
|
|
|
static void ro_msg_datasave_ack(wimp_message* message);
|
2003-11-08 02:51:13 +03:00
|
|
|
static void ro_msg_dataopen(wimp_message* block);
|
|
|
|
static char *ro_path_to_url(const char *path);
|
2002-09-11 18:24:02 +04:00
|
|
|
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
/**
|
|
|
|
* Initialise the gui (RISC OS specific part).
|
|
|
|
*/
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
void gui_init(int argc, char** argv)
|
|
|
|
{
|
2004-02-27 17:09:15 +03:00
|
|
|
char path[40];
|
2003-11-08 02:51:13 +03:00
|
|
|
char theme_fname[256];
|
2004-02-27 17:09:15 +03:00
|
|
|
os_error *error;
|
2003-08-25 02:39:55 +04:00
|
|
|
|
2004-03-05 16:23:48 +03:00
|
|
|
LOG(("starting hourglass"));
|
2004-01-28 21:37:56 +03:00
|
|
|
xhourglass_start(1);
|
|
|
|
|
2004-03-05 16:23:48 +03:00
|
|
|
LOG(("reading choices"));
|
2004-02-27 17:09:15 +03:00
|
|
|
options_read("Choices:WWW.NetSurf.Choices");
|
|
|
|
|
2004-03-05 16:23:48 +03:00
|
|
|
LOG(("choosing language"));
|
2004-02-27 17:09:15 +03:00
|
|
|
ro_gui_choose_language();
|
|
|
|
|
2004-03-05 16:23:48 +03:00
|
|
|
LOG(("grabbing NetSurf$Dir from the environment"));
|
2003-11-08 02:51:13 +03:00
|
|
|
NETSURF_DIR = getenv("NetSurf$Dir");
|
2004-02-27 17:09:15 +03:00
|
|
|
sprintf(path, "<NetSurf$Dir>.Resources.%s.Messages", option_language);
|
2004-03-05 16:23:48 +03:00
|
|
|
LOG(("Loading messages from '%s'", path));
|
2004-02-27 17:09:15 +03:00
|
|
|
messages_load(path);
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2004-03-05 16:23:48 +03:00
|
|
|
LOG(("done"));
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
task_handle = wimp_initialise(wimp_VERSION_RO38, "NetSurf",
|
|
|
|
(wimp_message_list*) &task_messages, 0);
|
2003-09-09 23:25:28 +04:00
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
/* Issue a *Desktop to poke AcornURI into life */
|
|
|
|
if (getenv("NetSurf$Start_URI_Handler"))
|
|
|
|
xwimp_start_task("Desktop", 0);
|
2003-09-05 18:35:36 +04:00
|
|
|
|
2004-02-13 19:09:12 +03:00
|
|
|
if (option_theme) {
|
2003-11-08 02:51:13 +03:00
|
|
|
snprintf(theme_fname, sizeof(theme_fname),
|
2004-02-13 19:09:12 +03:00
|
|
|
"<NetSurf$Dir>.Themes.%s", option_theme);
|
2003-11-08 02:51:13 +03:00
|
|
|
/* check if theme directory exists */
|
|
|
|
if (!is_dir(theme_fname)) {
|
2004-02-13 19:09:12 +03:00
|
|
|
free(option_theme);
|
|
|
|
option_theme = 0;
|
2003-11-08 02:51:13 +03:00
|
|
|
sprintf(theme_fname, "<NetSurf$Dir>.Themes.Default");
|
|
|
|
}
|
|
|
|
} else {
|
2004-02-13 19:09:12 +03:00
|
|
|
strcpy(theme_fname, "<NetSurf$Dir>.Themes.Default");
|
2003-11-08 02:51:13 +03:00
|
|
|
}
|
2003-11-20 03:16:31 +03:00
|
|
|
ro_theme_load(theme_fname);
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-27 17:09:15 +03:00
|
|
|
sprintf(path, "<NetSurf$Dir>.Resources.%s.Templates", option_language);
|
|
|
|
error = xwimp_open_template(path);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_open_template failed: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user(error->errmess);
|
|
|
|
exit(EXIT_FAILURE);
|
2003-12-30 01:50:43 +03:00
|
|
|
}
|
2003-11-08 02:51:13 +03:00
|
|
|
ro_gui_dialog_init();
|
|
|
|
ro_gui_download_init();
|
|
|
|
ro_gui_menus_init();
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_AUTH
|
2003-11-08 02:51:13 +03:00
|
|
|
ro_gui_401login_init();
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-11-15 03:26:42 +03:00
|
|
|
ro_gui_history_init();
|
2003-11-08 02:51:13 +03:00
|
|
|
wimp_close_template();
|
|
|
|
ro_gui_icon_bar_create();
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-02-27 17:09:15 +03:00
|
|
|
/**
|
|
|
|
* Determine the language to use.
|
|
|
|
*
|
|
|
|
* RISC OS has no standard way of determining which language the user prefers.
|
|
|
|
* We have to guess from the 'Country' setting.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_choose_language(void)
|
|
|
|
{
|
|
|
|
char path[40];
|
|
|
|
const char *lang;
|
|
|
|
int country;
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
/* if option_language exists and is valid, use that */
|
|
|
|
if (option_language) {
|
|
|
|
if (2 < strlen(option_language))
|
|
|
|
option_language[2] = 0;
|
|
|
|
sprintf(path, "<NetSurf$Dir>.Resources.%s", option_language);
|
|
|
|
if (is_dir(path))
|
|
|
|
return;
|
|
|
|
free(option_language);
|
|
|
|
option_language = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* choose a language from the configured country number */
|
|
|
|
error = xosbyte_read(osbyte_VAR_COUNTRY_NUMBER, &country);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosbyte_read failed: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
country = 1;
|
|
|
|
}
|
|
|
|
switch (country) {
|
|
|
|
case 6: /* France */
|
|
|
|
case 18: /* Canada2 (French Canada?) */
|
|
|
|
lang = "fr";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lang = "en";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sprintf(path, "<NetSurf$Dir>.Resources.%s", lang);
|
|
|
|
if (is_dir(path))
|
|
|
|
option_language = strdup(lang);
|
|
|
|
else
|
|
|
|
option_language = strdup("en");
|
|
|
|
assert(option_language);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
/**
|
|
|
|
* Create an iconbar icon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_icon_bar_create(void)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2003-11-08 02:51:13 +03:00
|
|
|
wimp_icon_create icon = {
|
|
|
|
wimp_ICON_BAR_RIGHT,
|
|
|
|
{ { 0, 0, 68, 68 },
|
|
|
|
wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED |
|
|
|
|
(wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT),
|
|
|
|
{ "!netsurf" } } };
|
|
|
|
wimp_create_icon(&icon);
|
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
/**
|
|
|
|
* Close down the gui (RISC OS).
|
|
|
|
*/
|
|
|
|
|
|
|
|
void gui_quit(void)
|
|
|
|
{
|
2003-11-15 03:26:42 +03:00
|
|
|
ro_gui_history_quit();
|
2003-11-08 02:51:13 +03:00
|
|
|
wimp_close_down(task_handle);
|
2004-01-28 21:37:56 +03:00
|
|
|
xhourglass_off();
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
/**
|
|
|
|
* Poll the OS for events (RISC OS).
|
|
|
|
*
|
|
|
|
* \param active return as soon as possible
|
|
|
|
*/
|
|
|
|
|
2003-11-06 22:41:41 +03:00
|
|
|
void gui_poll(bool active)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2004-01-28 21:37:56 +03:00
|
|
|
wimp_event_no event;
|
|
|
|
wimp_block block;
|
|
|
|
const wimp_poll_flags mask = wimp_MASK_LOSE | wimp_MASK_GAIN;
|
|
|
|
gui_window *g;
|
|
|
|
|
|
|
|
/* Process queued events. */
|
|
|
|
while (ro_gui_poll_queued_blocks) {
|
|
|
|
struct ro_gui_poll_block *next;
|
|
|
|
ro_gui_handle_event(ro_gui_poll_queued_blocks->event,
|
|
|
|
ro_gui_poll_queued_blocks->block);
|
|
|
|
next = ro_gui_poll_queued_blocks->next;
|
|
|
|
free(ro_gui_poll_queued_blocks->block);
|
|
|
|
free(ro_gui_poll_queued_blocks);
|
|
|
|
ro_gui_poll_queued_blocks = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Poll wimp. */
|
|
|
|
xhourglass_off();
|
|
|
|
if (active) {
|
|
|
|
event = wimp_poll(mask, &block, 0);
|
|
|
|
} else if (over_window || gui_reformat_pending) {
|
|
|
|
os_t t = os_read_monotonic_time();
|
|
|
|
event = wimp_poll_idle(mask, &block, t + 10, 0);
|
|
|
|
} else {
|
|
|
|
event = wimp_poll(wimp_MASK_NULL | mask, &block, 0);
|
|
|
|
}
|
|
|
|
xhourglass_on();
|
|
|
|
ro_gui_handle_event(event, &block);
|
|
|
|
|
|
|
|
if (gui_reformat_pending && event == wimp_NULL_REASON_CODE) {
|
2003-11-06 22:41:41 +03:00
|
|
|
for (g = window_list; g; g = g->next) {
|
|
|
|
if (g->type == GUI_BROWSER_WINDOW && g->data.browser.reformat_pending) {
|
|
|
|
content_reformat(g->data.browser.bw->current_content,
|
2004-02-25 18:12:58 +03:00
|
|
|
g->data.browser.old_width / 2 / g->scale,
|
|
|
|
1000);
|
2003-11-06 22:41:41 +03:00
|
|
|
g->data.browser.reformat_pending = false;
|
|
|
|
}
|
2003-09-11 01:44:11 +04:00
|
|
|
}
|
2003-11-06 22:41:41 +03:00
|
|
|
gui_reformat_pending = false;
|
2003-09-11 01:44:11 +04:00
|
|
|
}
|
2004-01-28 21:37:56 +03:00
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
|
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
/**
|
|
|
|
* Process a Wimp_Poll event.
|
|
|
|
*
|
|
|
|
* \param event wimp event number
|
|
|
|
* \param block parameter block
|
|
|
|
*/
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
void ro_gui_handle_event(wimp_event_no event, wimp_block *block)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case wimp_NULL_REASON_CODE:
|
|
|
|
ro_gui_null_reason_code();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wimp_REDRAW_WINDOW_REQUEST:
|
|
|
|
ro_gui_redraw_window_request(&block->redraw);
|
|
|
|
break;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_OPEN_WINDOW_REQUEST:
|
|
|
|
ro_gui_open_window_request(&block->open);
|
|
|
|
break;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_CLOSE_WINDOW_REQUEST:
|
|
|
|
ro_gui_close_window_request(&block->close);
|
|
|
|
break;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_POINTER_LEAVING_WINDOW:
|
|
|
|
over_window = 0;
|
|
|
|
break;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_POINTER_ENTERING_WINDOW:
|
|
|
|
over_window = ro_lookup_gui_from_w(block->entering.w);
|
|
|
|
break;
|
2003-12-21 05:27:22 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_MOUSE_CLICK:
|
|
|
|
ro_gui_mouse_click(&block->pointer);
|
|
|
|
break;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_USER_DRAG_BOX:
|
|
|
|
ro_gui_drag_end(&(block->dragged));
|
|
|
|
break;
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_KEY_PRESSED:
|
|
|
|
ro_gui_keypress(&(block->key));
|
|
|
|
break;
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_MENU_SELECTION:
|
|
|
|
ro_gui_menu_selection(&(block->selection));
|
|
|
|
break;
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_SCROLL_REQUEST:
|
|
|
|
ro_gui_scroll_request(&(block->scroll));
|
|
|
|
break;
|
2003-10-06 03:30:21 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_USER_MESSAGE:
|
|
|
|
case wimp_USER_MESSAGE_RECORDED:
|
|
|
|
case wimp_USER_MESSAGE_ACKNOWLEDGE:
|
|
|
|
ro_gui_user_message(event, &(block->message));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-07-30 17:06:22 +04:00
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
/**
|
|
|
|
* Check for important events and yield CPU (RISC OS).
|
|
|
|
*
|
|
|
|
* Required on RISC OS for cooperative multitasking.
|
|
|
|
*/
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
void gui_multitask(void)
|
|
|
|
{
|
|
|
|
wimp_event_no event;
|
|
|
|
wimp_block block;
|
|
|
|
|
|
|
|
xhourglass_off();
|
|
|
|
event = wimp_poll(wimp_MASK_LOSE | wimp_MASK_GAIN, &block, 0);
|
|
|
|
xhourglass_on();
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case wimp_CLOSE_WINDOW_REQUEST:
|
2004-02-23 03:25:09 +03:00
|
|
|
/* \todo close the window, and destroy content
|
|
|
|
* or abort loading of content */
|
|
|
|
break;
|
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
case wimp_KEY_PRESSED:
|
|
|
|
case wimp_MENU_SELECTION:
|
|
|
|
case wimp_USER_MESSAGE:
|
|
|
|
case wimp_USER_MESSAGE_RECORDED:
|
|
|
|
case wimp_USER_MESSAGE_ACKNOWLEDGE:
|
|
|
|
ro_gui_poll_queue(event, &block);
|
|
|
|
break;
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
default:
|
|
|
|
ro_gui_handle_event(event, &block);
|
|
|
|
break;
|
|
|
|
}
|
2003-11-08 02:51:13 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a wimp_block to the queue for later handling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_poll_queue(wimp_event_no event, wimp_block *block)
|
|
|
|
{
|
|
|
|
struct ro_gui_poll_block *q =
|
|
|
|
xcalloc(1, sizeof(struct ro_gui_poll_block));
|
|
|
|
|
|
|
|
q->event = event;
|
|
|
|
q->block = xcalloc(1, sizeof(*block));
|
|
|
|
memcpy(q->block, block, sizeof(*block));
|
|
|
|
q->next = NULL;
|
|
|
|
|
|
|
|
if (ro_gui_poll_queued_blocks == NULL) {
|
|
|
|
ro_gui_poll_queued_blocks = q;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
struct ro_gui_poll_block *current =
|
|
|
|
ro_gui_poll_queued_blocks;
|
|
|
|
while (current->next != NULL)
|
|
|
|
current = current->next;
|
|
|
|
current->next = q;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Null_Reason_Code events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_null_reason_code(void)
|
|
|
|
{
|
2004-02-26 03:44:42 +03:00
|
|
|
ro_gui_throb();
|
|
|
|
if (over_window) {
|
|
|
|
wimp_pointer pointer;
|
|
|
|
wimp_get_pointer_info(&pointer);
|
|
|
|
ro_gui_window_mouse_at(&pointer);
|
|
|
|
}
|
2004-01-28 21:37:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Redraw_Window_Request events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_redraw_window_request(wimp_draw *redraw)
|
2003-11-08 02:51:13 +03:00
|
|
|
{
|
2004-01-28 21:37:56 +03:00
|
|
|
gui_window *g;
|
|
|
|
|
|
|
|
if (redraw->w == dialog_config_th)
|
|
|
|
ro_gui_redraw_config_th(redraw);
|
|
|
|
else if (redraw->w == history_window)
|
|
|
|
ro_gui_history_redraw(redraw);
|
2003-11-08 02:51:13 +03:00
|
|
|
else {
|
2004-01-28 21:37:56 +03:00
|
|
|
g = ro_lookup_gui_from_w(redraw->w);
|
|
|
|
if (g != NULL)
|
|
|
|
ro_gui_window_redraw(g, redraw);
|
2003-11-08 02:51:13 +03:00
|
|
|
else {
|
2004-01-28 21:37:56 +03:00
|
|
|
osbool more = wimp_redraw_window(redraw);
|
2003-11-20 03:16:31 +03:00
|
|
|
while (more)
|
2004-01-28 21:37:56 +03:00
|
|
|
more = wimp_get_rectangle(redraw);
|
2003-11-08 02:51:13 +03:00
|
|
|
}
|
|
|
|
}
|
2004-01-28 21:37:56 +03:00
|
|
|
}
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2003-08-25 02:39:55 +04:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
/**
|
|
|
|
* Handle Open_Window_Request events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_open_window_request(wimp_open *open)
|
|
|
|
{
|
|
|
|
gui_window *g;
|
|
|
|
|
|
|
|
g = ro_lookup_gui_from_w(open->w);
|
|
|
|
if (g)
|
|
|
|
ro_gui_window_open(g, open);
|
|
|
|
else
|
|
|
|
wimp_open_window(open);
|
|
|
|
}
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
/**
|
|
|
|
* Handle Close_Window_Request events.
|
|
|
|
*/
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
void ro_gui_close_window_request(wimp_close *close)
|
|
|
|
{
|
|
|
|
gui_window *g;
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
g = ro_lookup_gui_from_w(close->w);
|
2004-02-23 03:25:09 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
if (g) {
|
|
|
|
browser_window_destroy(g->data.browser.bw
|
|
|
|
#ifdef WITH_FRAMES
|
|
|
|
, true
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
#ifdef WITH_COOKIES
|
|
|
|
clean_cookiejar();
|
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
ro_gui_dialog_close(close->w);
|
2003-11-08 02:51:13 +03:00
|
|
|
}
|
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Mouse_Click events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_mouse_click(wimp_pointer *pointer)
|
2003-11-08 02:51:13 +03:00
|
|
|
{
|
2004-01-28 21:37:56 +03:00
|
|
|
gui_window *g = ro_gui_window_lookup(pointer->w);
|
|
|
|
|
|
|
|
if (pointer->w == wimp_ICON_BAR)
|
|
|
|
ro_gui_icon_bar_click(pointer);
|
|
|
|
else if (pointer->w == history_window)
|
|
|
|
ro_gui_history_click(pointer);
|
2004-02-25 18:12:58 +03:00
|
|
|
else if (g && g->type == GUI_BROWSER_WINDOW && g->window == pointer->w)
|
|
|
|
ro_gui_window_click(g, pointer);
|
2004-01-28 21:37:56 +03:00
|
|
|
else if (g && g->type == GUI_BROWSER_WINDOW &&
|
|
|
|
g->data.browser.toolbar == pointer->w)
|
|
|
|
ro_gui_toolbar_click(g, pointer);
|
|
|
|
else if (g && g->type == GUI_DOWNLOAD_WINDOW)
|
|
|
|
ro_download_window_click(g, pointer);
|
2004-02-26 03:44:42 +03:00
|
|
|
else if (pointer->w == dialog_saveas)
|
|
|
|
ro_gui_save_click(pointer);
|
2004-01-28 21:37:56 +03:00
|
|
|
else
|
|
|
|
ro_gui_dialog_click(pointer);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
/**
|
|
|
|
* Handle Mouse_Click events on the iconbar icon.
|
|
|
|
*/
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
void ro_gui_icon_bar_click(wimp_pointer *pointer)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2004-01-28 21:37:56 +03:00
|
|
|
if (pointer->buttons == wimp_CLICK_MENU) {
|
|
|
|
ro_gui_create_menu(iconbar_menu, pointer->pos.x - 64,
|
|
|
|
96 + iconbar_menu_height, NULL);
|
|
|
|
} else if (pointer->buttons == wimp_CLICK_SELECT) {
|
2004-02-27 17:09:15 +03:00
|
|
|
char url[80];
|
|
|
|
sprintf(url, "file:///%%3CNetSurf$Dir%%3E/Docs/intro.%s",
|
|
|
|
option_language);
|
|
|
|
browser_window_create(url);
|
2004-01-28 21:37:56 +03:00
|
|
|
}
|
2002-10-15 14:41:12 +04:00
|
|
|
}
|
|
|
|
|
2003-12-11 04:23:57 +03:00
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
/**
|
|
|
|
* Handle User_Drag_Box events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_drag_end(wimp_dragged *drag)
|
|
|
|
{
|
|
|
|
switch (gui_current_drag_type) {
|
|
|
|
case GUI_DRAG_SELECTION:
|
|
|
|
ro_gui_selection_drag_end(drag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_DRAG_DOWNLOAD_SAVE:
|
|
|
|
ro_download_drag_end(drag);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_DRAG_SAVE:
|
|
|
|
ro_gui_save_drag_end(drag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-11 04:23:57 +03:00
|
|
|
/**
|
|
|
|
* Handle Key_Pressed events.
|
|
|
|
*/
|
2004-01-28 21:37:56 +03:00
|
|
|
|
2003-12-11 04:23:57 +03:00
|
|
|
void ro_gui_keypress(wimp_key *key)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2003-12-11 04:23:57 +03:00
|
|
|
bool handled = false;
|
|
|
|
gui_window *g = ro_gui_window_lookup(key->w);
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2003-12-11 04:23:57 +03:00
|
|
|
if (!g) {
|
2003-12-26 21:18:17 +03:00
|
|
|
handled = ro_gui_dialog_keypress(key);
|
|
|
|
if (!handled)
|
|
|
|
wimp_process_key(key->c);
|
2003-12-11 04:23:57 +03:00
|
|
|
return;
|
|
|
|
}
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2003-12-11 04:23:57 +03:00
|
|
|
switch (g->type) {
|
|
|
|
case GUI_BROWSER_WINDOW:
|
|
|
|
handled = ro_gui_window_keypress(g, key->c,
|
|
|
|
(bool) (g->data.browser.toolbar == key->w));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_DOWNLOAD_WINDOW:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
wimp_process_key(key->c);
|
2002-10-15 14:41:12 +04:00
|
|
|
}
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2003-12-11 04:23:57 +03:00
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
/**
|
|
|
|
* Handle the three User_Message events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_user_message(wimp_event_no event, wimp_message *message)
|
|
|
|
{
|
|
|
|
switch (message->action) {
|
|
|
|
case message_DATA_SAVE:
|
|
|
|
ro_msg_datasave(message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case message_DATA_SAVE_ACK:
|
|
|
|
ro_msg_datasave_ack(message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case message_DATA_LOAD:
|
|
|
|
ro_msg_dataload(message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case message_DATA_OPEN:
|
|
|
|
ro_msg_dataopen(message);
|
|
|
|
break;
|
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
case message_MENU_WARNING:
|
|
|
|
ro_gui_menu_warning((wimp_message_menu_warning *)
|
|
|
|
&message->data);
|
|
|
|
break;
|
|
|
|
|
2004-01-28 21:37:56 +03:00
|
|
|
#ifdef WITH_URI
|
|
|
|
case message_URI_PROCESS:
|
|
|
|
ro_uri_message_received(message);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_URL
|
|
|
|
case message_INET_SUITE_OPEN_URL:
|
|
|
|
ro_url_message_received(message);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
|
|
|
case message_PLUG_IN_OPENING:
|
|
|
|
case message_PLUG_IN_CLOSED:
|
|
|
|
case message_PLUG_IN_RESHAPE_REQUEST:
|
|
|
|
case message_PLUG_IN_FOCUS:
|
|
|
|
case message_PLUG_IN_URL_ACCESS:
|
|
|
|
case message_PLUG_IN_STATUS:
|
|
|
|
case message_PLUG_IN_BUSY:
|
|
|
|
case message_PLUG_IN_STREAM_NEW:
|
|
|
|
case message_PLUG_IN_STREAM_WRITE:
|
|
|
|
case message_PLUG_IN_STREAM_WRITTEN:
|
|
|
|
case message_PLUG_IN_STREAM_DESTROY:
|
|
|
|
case message_PLUG_IN_OPEN:
|
|
|
|
case message_PLUG_IN_CLOSE:
|
|
|
|
case message_PLUG_IN_RESHAPE:
|
|
|
|
case message_PLUG_IN_STREAM_AS_FILE:
|
|
|
|
case message_PLUG_IN_NOTIFY:
|
|
|
|
case message_PLUG_IN_ABORT:
|
|
|
|
case message_PLUG_IN_ACTION:
|
|
|
|
plugin_msg_parse(message,
|
|
|
|
event == wimp_USER_MESSAGE_ACKNOWLEDGE);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case message_QUIT:
|
|
|
|
netsurf_quit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
void gui_gadget_combo(struct browser_window* bw, struct form_control* g, unsigned long mx, unsigned long my)
|
2002-12-31 01:56:30 +03:00
|
|
|
{
|
|
|
|
int count = 0;
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_option* o;
|
2002-12-31 01:56:30 +03:00
|
|
|
wimp_pointer pointer;
|
2003-01-06 03:04:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
if (combo_menu != NULL)
|
|
|
|
xfree(combo_menu);
|
2003-01-06 03:04:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
o = g->data.select.items;
|
|
|
|
while (o != NULL)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
o = o->next;
|
|
|
|
}
|
|
|
|
|
2003-08-27 02:37:32 +04:00
|
|
|
combo_menu = xcalloc(1, wimp_SIZEOF_MENU(count));
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2004-02-27 20:45:19 +03:00
|
|
|
combo_menu->title_data.indirected_text.text =
|
|
|
|
messages_get("SelectMenu");
|
2002-12-31 01:56:30 +03:00
|
|
|
combo_menu->title_fg = wimp_COLOUR_BLACK;
|
|
|
|
combo_menu->title_bg = wimp_COLOUR_LIGHT_GREY;
|
|
|
|
combo_menu->work_fg = wimp_COLOUR_BLACK;
|
|
|
|
combo_menu->work_bg = wimp_COLOUR_WHITE;
|
|
|
|
combo_menu->width = 0;
|
|
|
|
combo_menu->height = wimp_MENU_ITEM_HEIGHT;
|
|
|
|
combo_menu->gap = wimp_MENU_ITEM_GAP;
|
|
|
|
|
|
|
|
o = g->data.select.items;
|
|
|
|
count = 0;
|
|
|
|
while (o != NULL)
|
|
|
|
{
|
|
|
|
combo_menu->entries[count].menu_flags = 0;
|
|
|
|
if (count == 0)
|
|
|
|
combo_menu->entries[count].menu_flags = wimp_MENU_TITLE_INDIRECTED;
|
|
|
|
if (o->selected)
|
|
|
|
combo_menu->entries[count].menu_flags |= wimp_MENU_TICKED;
|
|
|
|
if (o->next == NULL)
|
|
|
|
combo_menu->entries[count].menu_flags |= wimp_MENU_LAST;
|
|
|
|
|
|
|
|
combo_menu->entries[count].sub_menu = wimp_NO_SUB_MENU;
|
|
|
|
combo_menu->entries[count].icon_flags = wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_FILLED | wimp_ICON_VCENTRED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT) | (wimp_BUTTON_MENU_ICON << wimp_ICON_BUTTON_TYPE_SHIFT);
|
|
|
|
combo_menu->entries[count].data.indirected_text.text = o->text;
|
|
|
|
combo_menu->entries[count].data.indirected_text.validation = "\0";
|
|
|
|
combo_menu->entries[count].data.indirected_text.size = strlen(o->text);
|
|
|
|
count++;
|
|
|
|
o = o->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
wimp_get_pointer_info(&pointer);
|
|
|
|
current_gadget = g;
|
|
|
|
ro_gui_create_menu(combo_menu, pointer.pos.x - 64, pointer.pos.y, bw->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ro_msg_datasave(wimp_message* block)
|
|
|
|
{
|
|
|
|
gui_window* gui;
|
|
|
|
struct browser_window* bw;
|
2003-03-04 14:59:36 +03:00
|
|
|
wimp_message_data_xfer* data;
|
2002-12-31 01:56:30 +03:00
|
|
|
int x,y;
|
2003-12-27 03:11:57 +03:00
|
|
|
struct box_selection* click_boxes;
|
|
|
|
int found, plot_index;
|
|
|
|
int i;
|
|
|
|
wimp_window_state state;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2003-03-04 14:59:36 +03:00
|
|
|
data = &block->data.data_xfer;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
|
|
|
gui = ro_lookup_gui_from_w(data->w);
|
|
|
|
if (gui == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bw = gui->data.browser.bw;
|
|
|
|
|
2003-12-27 03:11:57 +03:00
|
|
|
state.w = data->w;
|
|
|
|
wimp_get_window_state(&state);
|
2004-02-25 18:12:58 +03:00
|
|
|
x = window_x_units(data->pos.x, &state) / 2;
|
|
|
|
y = -window_y_units(data->pos.y, &state) / 2;
|
2003-01-06 03:04:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
found = 0;
|
|
|
|
click_boxes = NULL;
|
|
|
|
plot_index = 0;
|
|
|
|
|
|
|
|
box_under_area(bw->current_content->data.html.layout->children,
|
2003-12-27 03:11:57 +03:00
|
|
|
(unsigned int)x, (unsigned int)y, 0, 0, &click_boxes,
|
|
|
|
&found, &plot_index);
|
2002-12-31 01:56:30 +03:00
|
|
|
|
|
|
|
if (found == 0)
|
2003-03-04 14:59:36 +03:00
|
|
|
return;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
|
|
|
for (i = found - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (click_boxes[i].box->gadget != NULL)
|
|
|
|
{
|
2003-03-04 14:59:36 +03:00
|
|
|
if (click_boxes[i].box->gadget->type == GADGET_TEXTAREA && data->file_type == 0xFFF)
|
2002-12-31 01:56:30 +03:00
|
|
|
{
|
|
|
|
/* load the text in! */
|
|
|
|
fprintf(stderr, "REPLYING TO MESSAGE MATE\n");
|
|
|
|
block->action = message_DATA_SAVE_ACK;
|
|
|
|
block->your_ref = block->my_ref;
|
|
|
|
block->my_ref = 0;
|
2003-03-04 14:59:36 +03:00
|
|
|
strcpy(block->data.data_xfer.file_name, "<Wimp$Scrap>");
|
2002-12-31 01:56:30 +03:00
|
|
|
wimp_send_message(wimp_USER_MESSAGE, block, block->sender);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-06 03:04:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
xfree(click_boxes);
|
|
|
|
}
|
|
|
|
|
2004-03-03 03:19:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Message_DataLoad (file dragged in).
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_msg_dataload(wimp_message *message)
|
2002-12-31 01:56:30 +03:00
|
|
|
{
|
2004-03-05 02:15:17 +03:00
|
|
|
char *url = 0;
|
2004-03-03 03:19:47 +03:00
|
|
|
|
|
|
|
if (message->data.data_xfer.w != wimp_ICON_BAR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (message->data.data_xfer.file_type != 0xfaf &&
|
|
|
|
message->data.data_xfer.file_type != 0x695 &&
|
|
|
|
message->data.data_xfer.file_type != 0xaff &&
|
|
|
|
message->data.data_xfer.file_type != 0xb60 &&
|
|
|
|
message->data.data_xfer.file_type != 0xc85 &&
|
2004-03-05 19:34:31 +03:00
|
|
|
message->data.data_xfer.file_type != 0xf91 &&
|
2004-03-03 03:19:47 +03:00
|
|
|
message->data.data_xfer.file_type != 0xff9 &&
|
2004-03-05 02:15:17 +03:00
|
|
|
message->data.data_xfer.file_type != 0xfff &&
|
|
|
|
message->data.data_xfer.file_type != 0xb28)
|
2004-03-03 03:19:47 +03:00
|
|
|
return;
|
|
|
|
|
2004-03-05 19:34:31 +03:00
|
|
|
/* uri file */
|
|
|
|
if (message->data.data_xfer.file_type == 0xf91) {
|
2004-03-05 19:55:31 +03:00
|
|
|
char *temp, *url1;
|
2004-03-05 19:34:31 +03:00
|
|
|
int i=0;
|
|
|
|
FILE *fp = fopen(message->data.data_xfer.file_name, "r");
|
|
|
|
|
|
|
|
if (!fp) return;
|
|
|
|
|
2004-03-05 19:55:31 +03:00
|
|
|
url1 = xcalloc(256, sizeof(char)); /* fixed size != good */
|
2004-03-05 19:34:31 +03:00
|
|
|
|
|
|
|
while (i != 2) {
|
2004-03-05 19:55:31 +03:00
|
|
|
temp = fgets(url1, 256, fp);
|
2004-03-05 19:34:31 +03:00
|
|
|
if (!temp) {
|
2004-03-05 20:08:28 +03:00
|
|
|
i = 2;
|
|
|
|
break;
|
2004-03-05 19:34:31 +03:00
|
|
|
}
|
|
|
|
|
2004-03-05 19:55:31 +03:00
|
|
|
temp = strip(url1);
|
|
|
|
url = xstrdup(temp);
|
2004-03-05 19:34:31 +03:00
|
|
|
if (url[0] != '#') { /* not a comment */
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2004-03-05 20:08:28 +03:00
|
|
|
|
|
|
|
xfree(url1);
|
|
|
|
if (!temp) return;
|
2004-03-05 19:34:31 +03:00
|
|
|
}
|
|
|
|
|
2004-03-05 02:15:17 +03:00
|
|
|
/* url file */
|
|
|
|
if (message->data.data_xfer.file_type == 0xb28) {
|
|
|
|
char *temp;
|
|
|
|
FILE *fp = fopen(message->data.data_xfer.file_name, "r");
|
|
|
|
|
|
|
|
if (!fp) return;
|
|
|
|
|
|
|
|
url = xcalloc(256, sizeof(char));
|
|
|
|
|
|
|
|
temp = fgets(url, 256, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
2004-03-05 16:23:48 +03:00
|
|
|
if (!temp) {
|
|
|
|
xfree(url);
|
|
|
|
return;
|
|
|
|
}
|
2004-03-05 02:15:17 +03:00
|
|
|
|
|
|
|
if (url[strlen(url)-1] == '\n') {
|
|
|
|
url[strlen(url)-1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-03 03:19:47 +03:00
|
|
|
/* send DataLoadAck */
|
|
|
|
message->action = message_DATA_LOAD_ACK;
|
|
|
|
message->your_ref = message->my_ref;
|
|
|
|
wimp_send_message(wimp_USER_MESSAGE, message, message->sender);
|
|
|
|
|
|
|
|
/* create a new window with the file */
|
2004-03-05 19:34:31 +03:00
|
|
|
if (message->data.data_xfer.file_type != 0xb28 &&
|
|
|
|
message->data.data_xfer.file_type != 0xf91) {
|
2004-03-05 02:15:17 +03:00
|
|
|
url = ro_path_to_url(message->data.data_xfer.file_name);
|
|
|
|
}
|
2004-03-03 03:19:47 +03:00
|
|
|
if (url) {
|
|
|
|
browser_window_create(url);
|
|
|
|
free(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
2002-12-31 01:56:30 +03:00
|
|
|
gui_window* gui;
|
|
|
|
struct browser_window* bw;
|
2003-03-04 14:59:36 +03:00
|
|
|
wimp_message_data_xfer* data;
|
2002-12-31 01:56:30 +03:00
|
|
|
int x,y;
|
2003-12-27 03:11:57 +03:00
|
|
|
struct box_selection* click_boxes;
|
|
|
|
int found, plot_index;
|
|
|
|
int i;
|
|
|
|
wimp_window_state state;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2003-03-04 14:59:36 +03:00
|
|
|
data = &block->data.data_xfer;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
|
|
|
gui = ro_lookup_gui_from_w(data->w);
|
|
|
|
if (gui == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bw = gui->data.browser.bw;
|
|
|
|
|
2003-12-27 03:11:57 +03:00
|
|
|
state.w = data->w;
|
|
|
|
wimp_get_window_state(&state);
|
2004-02-25 18:12:58 +03:00
|
|
|
x = window_x_units(data->pos.x, &state) / 2;
|
|
|
|
y = -window_y_units(data->pos.y, &state) / 2;
|
2003-01-06 03:04:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
found = 0;
|
|
|
|
click_boxes = NULL;
|
|
|
|
plot_index = 0;
|
|
|
|
|
|
|
|
box_under_area(bw->current_content->data.html.layout->children,
|
2003-12-27 03:11:57 +03:00
|
|
|
(unsigned int)x, (unsigned int)y, 0, 0, &click_boxes,
|
|
|
|
&found, &plot_index);
|
2002-12-31 01:56:30 +03:00
|
|
|
|
|
|
|
if (found == 0)
|
2003-03-04 14:59:36 +03:00
|
|
|
return;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
|
|
|
for (i = found - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (click_boxes[i].box->gadget != NULL)
|
|
|
|
{
|
2003-03-04 14:59:36 +03:00
|
|
|
if (click_boxes[i].box->gadget->type == GADGET_TEXTAREA && data->file_type == 0xFFF)
|
2002-12-31 01:56:30 +03:00
|
|
|
{
|
|
|
|
/* load the text in! */
|
2003-09-23 01:55:08 +04:00
|
|
|
/* TODO */
|
2002-12-31 01:56:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-06 03:04:43 +03:00
|
|
|
|
2002-12-31 01:56:30 +03:00
|
|
|
xfree(click_boxes);
|
2004-03-03 03:19:47 +03:00
|
|
|
#endif
|
2002-12-31 01:56:30 +03:00
|
|
|
}
|
|
|
|
|
2003-09-11 01:44:11 +04:00
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
/**
|
|
|
|
* Handle Message_DataSaveAck.
|
|
|
|
*/
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
void ro_msg_datasave_ack(wimp_message *message)
|
2003-11-08 02:51:13 +03:00
|
|
|
{
|
2004-02-26 03:44:42 +03:00
|
|
|
switch (gui_current_drag_type) {
|
|
|
|
case GUI_DRAG_DOWNLOAD_SAVE:
|
|
|
|
ro_download_datasave_ack(message);
|
|
|
|
break;
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
case GUI_DRAG_SAVE:
|
|
|
|
ro_gui_save_datasave_ack(message);
|
|
|
|
break;
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-11-08 02:51:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Message_DataOpen (double-click on file in the Filer).
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_msg_dataopen(wimp_message *message)
|
|
|
|
{
|
2004-03-05 02:15:17 +03:00
|
|
|
char *url = 0;
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-03-05 02:15:17 +03:00
|
|
|
if (message->data.data_xfer.file_type != 0xfaf &&
|
|
|
|
message->data.data_xfer.file_type != 0xb28)
|
|
|
|
/* ignore all but HTML and URL */
|
2003-11-08 02:51:13 +03:00
|
|
|
return;
|
|
|
|
|
2004-03-05 02:15:17 +03:00
|
|
|
/* url file */
|
|
|
|
if (message->data.data_xfer.file_type == 0xb28) {
|
|
|
|
char *temp;
|
|
|
|
FILE *fp = fopen(message->data.data_xfer.file_name, "r");
|
|
|
|
|
|
|
|
if (!fp) return;
|
|
|
|
|
|
|
|
url = xcalloc(256, sizeof(char));
|
|
|
|
|
|
|
|
temp = fgets(url, 256, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
2004-03-05 16:23:48 +03:00
|
|
|
if (!temp) {
|
|
|
|
xfree(url);
|
|
|
|
return;
|
|
|
|
}
|
2004-03-05 02:15:17 +03:00
|
|
|
|
|
|
|
if (url[strlen(url)-1] == '\n') {
|
|
|
|
url[strlen(url)-1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
/* send DataLoadAck */
|
|
|
|
message->action = message_DATA_LOAD_ACK;
|
|
|
|
message->your_ref = message->my_ref;
|
|
|
|
wimp_send_message(wimp_USER_MESSAGE, message, message->sender);
|
|
|
|
|
|
|
|
/* create a new window with the file */
|
2004-03-05 02:15:17 +03:00
|
|
|
if (message->data.data_xfer.file_type != 0xb28) {
|
|
|
|
url = ro_path_to_url(message->data.data_xfer.file_name);
|
|
|
|
}
|
2004-03-03 03:19:47 +03:00
|
|
|
if (url) {
|
|
|
|
browser_window_create(url);
|
|
|
|
free(url);
|
|
|
|
}
|
2003-11-08 02:51:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a RISC OS pathname to a file: URL.
|
2004-03-03 03:19:47 +03:00
|
|
|
*
|
|
|
|
* \param path RISC OS pathname
|
|
|
|
* \return URL, allocated on heap, or 0 on failure
|
2003-11-08 02:51:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
char *ro_path_to_url(const char *path)
|
|
|
|
{
|
2004-03-03 03:19:47 +03:00
|
|
|
int spare;
|
|
|
|
char *buffer = 0;
|
|
|
|
char *url = 0;
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
error = xosfscontrol_canonicalise_path(path, 0, 0, 0, 0, &spare);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user(error->errmess);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = malloc(1 - spare);
|
|
|
|
url = malloc(1 - spare + 10);
|
|
|
|
if (!buffer || !url) {
|
|
|
|
LOG(("malloc failed"));
|
|
|
|
warn_user("NoMemory");
|
|
|
|
free(buffer);
|
|
|
|
free(url);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = xosfscontrol_canonicalise_path(path, buffer, 0, 0, 1 - spare,
|
|
|
|
0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user(error->errmess);
|
|
|
|
free(buffer);
|
|
|
|
free(url);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(url, "file:");
|
|
|
|
__unixify(buffer, __RISCOSIFY_NO_REVERSE_SUFFIX, url + 5,
|
|
|
|
1 - spare + 5, 0);
|
|
|
|
free(buffer);
|
2003-11-08 02:51:13 +03:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-11 01:44:11 +04:00
|
|
|
/**
|
|
|
|
* Find screen size in OS units.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_screen_size(int *width, int *height)
|
|
|
|
{
|
|
|
|
int xeig_factor, yeig_factor, xwind_limit, ywind_limit;
|
|
|
|
|
|
|
|
os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XEIG_FACTOR, &xeig_factor);
|
|
|
|
os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YEIG_FACTOR, &yeig_factor);
|
|
|
|
os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XWIND_LIMIT, &xwind_limit);
|
|
|
|
os_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YWIND_LIMIT, &ywind_limit);
|
|
|
|
*width = (xwind_limit + 1) << xeig_factor;
|
|
|
|
*height = (ywind_limit + 1) << yeig_factor;
|
|
|
|
}
|
|
|
|
|
2003-11-08 02:51:13 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
void ro_gui_open_help_page(void)
|
2003-09-26 20:52:53 +04:00
|
|
|
{
|
2004-02-27 17:09:15 +03:00
|
|
|
char url[80];
|
|
|
|
sprintf(url, "file:///%%3CNetSurf$Dir%%3E/Docs/docs.%s",
|
|
|
|
option_language);
|
|
|
|
browser_window_create(url);
|
2003-09-26 20:52:53 +04:00
|
|
|
}
|
|
|
|
|
2003-12-11 04:23:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the source of a content to a text editor.
|
|
|
|
*/
|
2004-02-26 03:44:42 +03:00
|
|
|
|
2003-12-11 04:23:57 +03:00
|
|
|
void ro_gui_view_source(struct content *content)
|
|
|
|
{
|
|
|
|
|
2004-01-20 23:13:43 +03:00
|
|
|
if (content->type == CONTENT_HTML) {
|
|
|
|
xosfile_save_stamped("<Wimp$Scrap>", 0xfff,
|
|
|
|
content->data.html.source,
|
|
|
|
(content->data.html.source +
|
|
|
|
content->data.html.length));
|
|
|
|
xos_cli("Filer_Run <Wimp$Scrap>");
|
|
|
|
xosfile_set_type("<Wimp$Scrap>", 0xfaf);
|
|
|
|
}
|
|
|
|
else if (content->type == CONTENT_CSS) {
|
|
|
|
xosfile_save_stamped("<Wimp$Scrap>", 0xfff,
|
|
|
|
content->data.css.data,
|
|
|
|
(content->data.css.data +
|
|
|
|
content->data.css.length));
|
|
|
|
xos_cli("Filer_Run <Wimp$Scrap>");
|
|
|
|
xosfile_set_type("<Wimp$Scrap>", 0xf79);
|
|
|
|
}
|
2003-12-11 04:23:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
static os_error warn_error = { 1, "" };
|
2003-10-06 03:30:21 +04:00
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Display a warning for a serious problem (eg memory exhaustion).
|
|
|
|
*
|
|
|
|
* \param warning message key for warning message
|
|
|
|
*/
|
2003-10-06 03:30:21 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
void warn_user(const char *warning)
|
2003-11-08 02:51:13 +03:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
strncpy(warn_error.errmess, messages_get(warning), 252);
|
|
|
|
/** \todo get rid of cancel button, appears for unknown reason */
|
|
|
|
xwimp_report_error_by_category(&warn_error,
|
|
|
|
wimp_ERROR_BOX_OK_ICON |
|
|
|
|
wimp_ERROR_BOX_GIVEN_CATEGORY |
|
|
|
|
wimp_ERROR_BOX_CATEGORY_PROGRAM,
|
|
|
|
"NetSurf", "!netsurf",
|
|
|
|
(osspriteop_area *) 1, 0, 0);
|
2003-10-06 03:30:21 +04:00
|
|
|
}
|