mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-23 14:59:47 +03:00
[project @ 2004-02-26 00:44:42 by bursa]
Implement drag saving of drawfiles and clean up drag/drop/save code. svn path=/import/netsurf/; revision=568
This commit is contained in:
parent
4b5a0e4043
commit
318869e90e
@ -12,6 +12,8 @@ Page:Page
|
||||
PageInfo:Info...
|
||||
Save:Save
|
||||
Export:Export
|
||||
ExportAs:Export as
|
||||
Draw:Draw
|
||||
Print:Print...
|
||||
Selection:Selection
|
||||
Copy:Copy to clipboard
|
||||
|
Binary file not shown.
2
makefile
2
makefile
@ -18,7 +18,7 @@ OBJECTS = $(OBJECTS_COMMON) \
|
||||
textselection.o theme.o window.o \
|
||||
draw.o gif.o jpeg.o plugin.o png.o sprite.o \
|
||||
about.o filetype.o font.o uri.o url.o history.o \
|
||||
version.o save_draw.o save_complete.o thumbnail.o
|
||||
version.o save_draw.o save_complete.o thumbnail.o save.o
|
||||
OBJECTS_DEBUG = $(OBJECTS_COMMON) \
|
||||
netsurfd.o \
|
||||
options.o filetyped.o fontd.o
|
||||
|
@ -55,8 +55,6 @@ static void ro_gui_build_theme_menu(void);
|
||||
static int file_exists(const char* base, const char* dir, const char* leaf, bits ftype);
|
||||
static void set_icon_state(wimp_w w, wimp_i i, int state);
|
||||
static int get_icon_state(wimp_w w, wimp_i i);
|
||||
static void set_icon_string(wimp_w w, wimp_i i, const char *text);
|
||||
static char* get_icon_string(wimp_w w, wimp_i i);
|
||||
static void set_icon_string_i(wimp_w w, wimp_i i, int num);
|
||||
|
||||
|
||||
@ -68,7 +66,7 @@ void ro_gui_dialog_init(void)
|
||||
{
|
||||
dialog_info = ro_gui_dialog_create("info");
|
||||
/* fill in about box version info */
|
||||
set_icon_string(dialog_info, 4, netsurf_version);
|
||||
ro_gui_set_icon_string(dialog_info, 4, netsurf_version);
|
||||
|
||||
dialog_saveas = ro_gui_dialog_create("saveas");
|
||||
dialog_config = ro_gui_dialog_create("config");
|
||||
@ -290,9 +288,9 @@ void ro_gui_dialog_update_config_br(void)
|
||||
{
|
||||
char s[10];
|
||||
sprintf(s, "%i.%ipt", font_size / 10, font_size % 10);
|
||||
set_icon_string(dialog_config_br, ICON_CONFIG_BR_FONTSIZE, s);
|
||||
ro_gui_set_icon_string(dialog_config_br, ICON_CONFIG_BR_FONTSIZE, s);
|
||||
sprintf(s, "%i.%ipt", font_min_size / 10, font_min_size % 10);
|
||||
set_icon_string(dialog_config_br, ICON_CONFIG_BR_MINSIZE, s);
|
||||
ro_gui_set_icon_string(dialog_config_br, ICON_CONFIG_BR_MINSIZE, s);
|
||||
}
|
||||
|
||||
|
||||
@ -357,7 +355,7 @@ void ro_gui_dialog_click_config_th(wimp_pointer *pointer)
|
||||
void ro_gui_dialog_click_zoom(wimp_pointer *pointer)
|
||||
{
|
||||
unsigned int scale;
|
||||
scale = atoi(get_icon_string(dialog_zoom, ICON_ZOOM_VALUE));
|
||||
scale = atoi(ro_gui_get_icon_string(dialog_zoom, ICON_ZOOM_VALUE));
|
||||
|
||||
switch (pointer->i) {
|
||||
case ICON_ZOOM_DEC: scale -= 10; break;
|
||||
@ -440,7 +438,7 @@ void set_proxy_choices(void)
|
||||
{
|
||||
set_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP,
|
||||
option_http_proxy);
|
||||
set_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST,
|
||||
ro_gui_set_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST,
|
||||
option_http_proxy_host ? option_http_proxy_host : "");
|
||||
set_icon_string_i(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT,
|
||||
option_http_proxy_port);
|
||||
@ -456,9 +454,9 @@ void get_proxy_choices(void)
|
||||
option_http_proxy = get_icon_state(dialog_config_prox,
|
||||
ICON_CONFIG_PROX_HTTP);
|
||||
free(option_http_proxy_host);
|
||||
option_http_proxy_host = strdup(get_icon_string(dialog_config_prox,
|
||||
option_http_proxy_host = strdup(ro_gui_get_icon_string(dialog_config_prox,
|
||||
ICON_CONFIG_PROX_HTTPHOST));
|
||||
option_http_proxy_port = atoi(get_icon_string(dialog_config_prox,
|
||||
option_http_proxy_port = atoi(ro_gui_get_icon_string(dialog_config_prox,
|
||||
ICON_CONFIG_PROX_HTTPPORT));
|
||||
}
|
||||
|
||||
@ -469,7 +467,7 @@ void get_proxy_choices(void)
|
||||
|
||||
void set_theme_choices(void)
|
||||
{
|
||||
set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME,
|
||||
ro_gui_set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME,
|
||||
option_theme ? option_theme : "Default");
|
||||
load_theme_preview(option_theme ? option_theme : "Default");
|
||||
}
|
||||
@ -482,7 +480,7 @@ void set_theme_choices(void)
|
||||
void get_theme_choices(void)
|
||||
{
|
||||
free(option_theme);
|
||||
option_theme = strdup(get_icon_string(dialog_config_th,
|
||||
option_theme = strdup(ro_gui_get_icon_string(dialog_config_th,
|
||||
ICON_CONFIG_TH_NAME));
|
||||
}
|
||||
|
||||
@ -661,7 +659,7 @@ void ro_gui_build_theme_menu(void)
|
||||
|
||||
void ro_gui_theme_menu_selection(char *theme)
|
||||
{
|
||||
set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme);
|
||||
ro_gui_set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme);
|
||||
load_theme_preview(theme);
|
||||
wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_PREVIEW, 0, 0);
|
||||
}
|
||||
@ -711,7 +709,7 @@ int get_icon_state(wimp_w w, wimp_i i)
|
||||
* \param text string (copied)
|
||||
*/
|
||||
|
||||
void set_icon_string(wimp_w w, wimp_i i, const char *text)
|
||||
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text)
|
||||
{
|
||||
wimp_icon_state ic;
|
||||
ic.w = w;
|
||||
@ -722,7 +720,16 @@ void set_icon_string(wimp_w w, wimp_i i, const char *text)
|
||||
wimp_set_icon_state(w, i, 0, 0);
|
||||
}
|
||||
|
||||
char* get_icon_string(wimp_w w, wimp_i i)
|
||||
|
||||
/**
|
||||
* Read the contents of an icon.
|
||||
*
|
||||
* \param w window handle
|
||||
* \param i icon handle
|
||||
* \return string in icon
|
||||
*/
|
||||
|
||||
char *ro_gui_get_icon_string(wimp_w w, wimp_i i)
|
||||
{
|
||||
wimp_icon_state ic;
|
||||
ic.w = w;
|
||||
@ -735,6 +742,6 @@ void set_icon_string_i(wimp_w w, wimp_i i, int num)
|
||||
{
|
||||
char buffer[255];
|
||||
sprintf(buffer, "%d", num);
|
||||
set_icon_string(w, i, buffer);
|
||||
ro_gui_set_icon_string(w, i, buffer);
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,14 @@
|
||||
* 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 James Bursa <bursa@users.sourceforge.net>
|
||||
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
||||
* Copyright 2003 Rob Jackson <jacko@xms.ms>
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "oslib/mimemap.h"
|
||||
#include "oslib/osfile.h"
|
||||
#include "oslib/wimp.h"
|
||||
#include "oslib/wimpspriteop.h"
|
||||
#include "netsurf/desktop/gui.h"
|
||||
@ -77,13 +79,13 @@ gui_window *gui_create_download_window(struct content *content)
|
||||
g->status;
|
||||
download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text.size =
|
||||
256;
|
||||
sprintf(g->data.download.sprite_name, "Sfile_%x",
|
||||
sprintf(g->data.download.sprite_name, "file_%x",
|
||||
g->data.download.file_type);
|
||||
e = xwimpspriteop_select_sprite(g->data.download.sprite_name + 1, 0);
|
||||
e = xwimpspriteop_select_sprite(g->data.download.sprite_name, 0);
|
||||
if (e)
|
||||
strcpy(g->data.download.sprite_name, "Sfile_xxx");
|
||||
download_template->icons[ICON_DOWNLOAD_ICON].data.indirected_text.validation =
|
||||
g->data.download.sprite_name;
|
||||
strcpy(g->data.download.sprite_name, "file_xxx");
|
||||
download_template->icons[ICON_DOWNLOAD_ICON].data.indirected_sprite.id =
|
||||
(osspriteop_id) g->data.download.sprite_name;
|
||||
ro_gui_download_leaf(content->url, g->data.download.path);
|
||||
download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.text =
|
||||
g->data.download.path;
|
||||
@ -191,31 +193,91 @@ void gui_download_window_done(gui_window *g)
|
||||
g->data.download.download_status = download_COMPLETE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle clicks in a download window.
|
||||
*/
|
||||
|
||||
void ro_download_window_click(struct gui_window *g, wimp_pointer *pointer)
|
||||
{
|
||||
/* Handle clicks on download windows */
|
||||
switch (pointer->i) {
|
||||
case ICON_DOWNLOAD_ABORT:
|
||||
if (g->data.download.download_status ==
|
||||
download_INCOMPLETE)
|
||||
fetch_abort(g->data.download.content->fetch);
|
||||
|
||||
switch (pointer->i)
|
||||
{
|
||||
case ICON_DOWNLOAD_ABORT : if (g->data.download.download_status ==
|
||||
download_INCOMPLETE)
|
||||
fetch_abort(g->data.download.content->fetch);
|
||||
ro_download_window_close(g);
|
||||
break;
|
||||
|
||||
ro_download_window_close(g);
|
||||
break;
|
||||
|
||||
case ICON_DOWNLOAD_ICON : if (g->data.download.download_status ==
|
||||
download_COMPLETE)
|
||||
{
|
||||
current_drag.type = draginfo_DOWNLOAD_SAVE;
|
||||
current_drag.data.download.gui = g;
|
||||
ro_gui_drag_box_start(pointer);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ICON_DOWNLOAD_ICON:
|
||||
if (g->data.download.download_status ==
|
||||
download_COMPLETE) {
|
||||
gui_current_drag_type = GUI_DRAG_DOWNLOAD_SAVE;
|
||||
current_gui = g;
|
||||
ro_gui_drag_icon(pointer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle User_Drag_Box event for a drag from a download window.
|
||||
*/
|
||||
|
||||
void ro_download_drag_end(wimp_dragged *drag)
|
||||
{
|
||||
wimp_pointer pointer;
|
||||
wimp_message message;
|
||||
|
||||
wimp_get_pointer_info(&pointer);
|
||||
|
||||
message.your_ref = 0;
|
||||
message.action = message_DATA_SAVE;
|
||||
message.data.data_xfer.w = pointer.w;
|
||||
message.data.data_xfer.i = pointer.i;
|
||||
message.data.data_xfer.pos.x = pointer.pos.x;
|
||||
message.data.data_xfer.pos.y = pointer.pos.y;
|
||||
message.data.data_xfer.est_size = (int)
|
||||
current_gui->data.download.content->data.other.length;
|
||||
message.data.data_xfer.file_type = current_gui->data.download.file_type;
|
||||
strncpy(message.data.data_xfer.file_name,
|
||||
current_gui->data.download.path, 212);
|
||||
message.size = 44 + ((strlen(message.data.data_xfer.file_name) + 4) &
|
||||
(~3u));
|
||||
|
||||
wimp_send_message_to_window(wimp_USER_MESSAGE, &message,
|
||||
pointer.w, pointer.i);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle Message_DataSaveAck for a drag from a download window.
|
||||
*/
|
||||
|
||||
void ro_download_datasave_ack(wimp_message *message)
|
||||
{
|
||||
char *data;
|
||||
char *data_end;
|
||||
os_error *error;
|
||||
|
||||
assert(current_gui->data.download.download_status == download_COMPLETE);
|
||||
|
||||
data = current_gui->data.download.content->data.other.data;
|
||||
data_end = data + current_gui->data.download.content->data.other.length;
|
||||
|
||||
error = xosfile_save_stamped(message->data.data_xfer.file_name,
|
||||
current_gui->data.download.file_type,
|
||||
data, data_end);
|
||||
if (error) {
|
||||
LOG(("0x%x: %s\n", error->errnum, error->errmess));
|
||||
warn_user(error->errmess);
|
||||
} else {
|
||||
ro_download_window_close(current_gui);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct gui_window * ro_lookup_download_window_from_w(wimp_w window)
|
||||
{
|
||||
gui_window* g;
|
||||
|
161
riscos/gui.c
161
riscos/gui.c
@ -57,13 +57,15 @@ 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. */
|
||||
gui_drag_type gui_current_drag_type;
|
||||
static wimp_t task_handle; /**< RISC OS wimp task handle. */
|
||||
/** Accepted wimp user messages. */
|
||||
static const wimp_MESSAGE_LIST(25) task_messages = { {
|
||||
static const wimp_MESSAGE_LIST(26) task_messages = { {
|
||||
message_DATA_SAVE,
|
||||
message_DATA_SAVE_ACK,
|
||||
message_DATA_LOAD,
|
||||
message_DATA_OPEN,
|
||||
message_MENU_WARNING,
|
||||
#ifdef WITH_URI
|
||||
message_URI_PROCESS,
|
||||
#endif
|
||||
@ -110,12 +112,12 @@ 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);
|
||||
static void ro_gui_icon_bar_click(wimp_pointer* pointer);
|
||||
static void ro_gui_drag_end(wimp_dragged *drag);
|
||||
static void ro_gui_keypress(wimp_key* key);
|
||||
static void ro_gui_user_message(wimp_event_no event, wimp_message *message);
|
||||
static void ro_msg_datasave(wimp_message* block);
|
||||
static void ro_msg_dataload(wimp_message* block);
|
||||
static void ro_msg_datasave_ack(wimp_message* message);
|
||||
static int ro_save_data(void *data, unsigned long length, char *file_name, bits file_type);
|
||||
static void ro_msg_dataopen(wimp_message* block);
|
||||
static char *ro_path_to_url(const char *path);
|
||||
|
||||
@ -388,14 +390,12 @@ void ro_gui_poll_queue(wimp_event_no event, wimp_block *block)
|
||||
|
||||
void ro_gui_null_reason_code(void)
|
||||
{
|
||||
ro_gui_throb();
|
||||
if (over_window != NULL
|
||||
|| current_drag.type == draginfo_BROWSER_TEXT_SELECTION)
|
||||
{
|
||||
wimp_pointer pointer;
|
||||
wimp_get_pointer_info(&pointer);
|
||||
ro_gui_window_mouse_at(&pointer);
|
||||
}
|
||||
ro_gui_throb();
|
||||
if (over_window) {
|
||||
wimp_pointer pointer;
|
||||
wimp_get_pointer_info(&pointer);
|
||||
ro_gui_window_mouse_at(&pointer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -483,6 +483,8 @@ void ro_gui_mouse_click(wimp_pointer *pointer)
|
||||
ro_gui_toolbar_click(g, pointer);
|
||||
else if (g && g->type == GUI_DOWNLOAD_WINDOW)
|
||||
ro_download_window_click(g, pointer);
|
||||
else if (pointer->w == dialog_saveas)
|
||||
ro_gui_save_click(pointer);
|
||||
else
|
||||
ro_gui_dialog_click(pointer);
|
||||
}
|
||||
@ -503,6 +505,28 @@ void ro_gui_icon_bar_click(wimp_pointer *pointer)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle Key_Pressed events.
|
||||
*/
|
||||
@ -557,6 +581,11 @@ void ro_gui_user_message(wimp_event_no event, wimp_message *message)
|
||||
ro_msg_dataopen(message);
|
||||
break;
|
||||
|
||||
case message_MENU_WARNING:
|
||||
ro_gui_menu_warning((wimp_message_menu_warning *)
|
||||
&message->data);
|
||||
break;
|
||||
|
||||
#ifdef WITH_URI
|
||||
case message_URI_PROCESS:
|
||||
ro_uri_message_received(message);
|
||||
@ -758,52 +787,24 @@ void ro_msg_dataload(wimp_message* block)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle Message_DataSaveAck.
|
||||
*/
|
||||
|
||||
void ro_msg_datasave_ack(wimp_message *message)
|
||||
{
|
||||
int save_status = 0;
|
||||
switch (gui_current_drag_type) {
|
||||
case GUI_DRAG_DOWNLOAD_SAVE:
|
||||
ro_download_datasave_ack(message);
|
||||
break;
|
||||
|
||||
LOG(("ACK Message: filename = %s", message->data.data_xfer.file_name));
|
||||
case GUI_DRAG_SAVE:
|
||||
ro_gui_save_datasave_ack(message);
|
||||
break;
|
||||
|
||||
if (current_drag.type == draginfo_DOWNLOAD_SAVE)
|
||||
{
|
||||
assert(current_drag.data.download.gui->data.download.download_status ==
|
||||
download_COMPLETE);
|
||||
|
||||
|
||||
save_status = ro_save_data(current_drag.data.download.gui->data.download.content->data.other.data,
|
||||
current_drag.data.download.gui->data.download.content->data.other.length,
|
||||
message->data.data_xfer.file_name,
|
||||
current_drag.data.download.gui->data.download.file_type);
|
||||
|
||||
|
||||
if (save_status != 1)
|
||||
{
|
||||
LOG(("Could not save download data"));
|
||||
//Report_Error
|
||||
}
|
||||
else
|
||||
{
|
||||
ro_download_window_close(current_drag.data.download.gui);
|
||||
current_drag.type = draginfo_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ro_save_data(void *data, unsigned long length, char *file_name, bits file_type)
|
||||
{
|
||||
os_error *written = NULL;
|
||||
|
||||
void *end_data = (void*)((int)data + length);
|
||||
|
||||
written = xosfile_save_stamped(file_name, file_type, data, end_data);
|
||||
|
||||
if (written != NULL)
|
||||
{
|
||||
LOG(("Unable to create stamped file"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -871,6 +872,7 @@ void ro_gui_open_help_page(void)
|
||||
/**
|
||||
* Send the source of a content to a text editor.
|
||||
*/
|
||||
|
||||
void ro_gui_view_source(struct content *content)
|
||||
{
|
||||
|
||||
@ -893,61 +895,6 @@ void ro_gui_view_source(struct content *content)
|
||||
}
|
||||
|
||||
|
||||
void ro_gui_drag_box_start(wimp_pointer *pointer)
|
||||
{
|
||||
wimp_drag *drag_box;
|
||||
wimp_window_state *icon_window;
|
||||
wimp_icon_state *icon_icon;
|
||||
int x0, y0;
|
||||
|
||||
/* TODO: support drag_a_sprite */
|
||||
|
||||
icon_window = xcalloc(1, sizeof(*icon_window));
|
||||
icon_icon = xcalloc(1, sizeof(*icon_icon));
|
||||
drag_box = xcalloc(1, sizeof(*drag_box));
|
||||
|
||||
drag_box->w = pointer->w;
|
||||
drag_box->type = wimp_DRAG_USER_FIXED;
|
||||
|
||||
icon_window->w = pointer->w;
|
||||
wimp_get_window_state(icon_window);
|
||||
|
||||
x0 = icon_window->visible.x0 - icon_window->xscroll;
|
||||
y0 = icon_window->visible.y1 - icon_window->yscroll;
|
||||
|
||||
icon_icon->w = pointer->w;
|
||||
icon_icon->i = pointer->i;
|
||||
wimp_get_icon_state(icon_icon);
|
||||
|
||||
drag_box->initial.x0 = x0 + icon_icon->icon.extent.x0;
|
||||
drag_box->initial.y0 = y0 + icon_icon->icon.extent.y0;
|
||||
drag_box->initial.x1 = x0 + icon_icon->icon.extent.x1;
|
||||
drag_box->initial.y1 = y0 + icon_icon->icon.extent.y1;
|
||||
|
||||
drag_box->bbox.x0 = 0x80000000;
|
||||
drag_box->bbox.y0 = 0x80000000;
|
||||
drag_box->bbox.x1 = 0x7FFFFFFF; // CHANGE
|
||||
drag_box->bbox.y1 = 0x7FFFFFFF;
|
||||
|
||||
/*if(USE_DRAGASPRITE == DRAGASPRITE_AVAILABLE)
|
||||
xdragasprite_start((dragasprite_HPOS_CENTRE ^
|
||||
dragasprite_VPOS_CENTRE ^
|
||||
dragasprite_NO_BOUND ^
|
||||
dragasprite_BOUND_POINTER),
|
||||
(osspriteop_area*) 1,
|
||||
"file_fff",
|
||||
(os_box*)&drag_box->initial,0);*/
|
||||
|
||||
wimp_drag_box(drag_box);
|
||||
|
||||
xfree(drag_box);
|
||||
xfree(icon_window);
|
||||
xfree(icon_icon);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static os_error warn_error = { 1, "" };
|
||||
|
||||
|
||||
|
42
riscos/gui.h
42
riscos/gui.h
@ -31,6 +31,11 @@ extern bool gui_redraw_debug;
|
||||
extern gui_window *current_gui;
|
||||
|
||||
typedef enum { GUI_BROWSER_WINDOW, GUI_DOWNLOAD_WINDOW } gui_window_type;
|
||||
typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW } gui_save_type;
|
||||
extern gui_save_type gui_current_save_type;
|
||||
typedef enum { GUI_DRAG_SELECTION, GUI_DRAG_DOWNLOAD_SAVE,
|
||||
GUI_DRAG_SAVE } gui_drag_type;
|
||||
extern gui_drag_type gui_current_drag_type;
|
||||
|
||||
struct gui_window
|
||||
{
|
||||
@ -74,22 +79,6 @@ struct gui_window
|
||||
float scale;
|
||||
};
|
||||
|
||||
struct ro_gui_drag_info
|
||||
{
|
||||
enum { draginfo_UNKNOWN, draginfo_NONE, draginfo_BROWSER_TEXT_SELECTION, draginfo_DOWNLOAD_SAVE } type;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
gui_window* gui;
|
||||
} selection;
|
||||
|
||||
struct
|
||||
{
|
||||
gui_window* gui;
|
||||
} download;
|
||||
} data;
|
||||
};
|
||||
|
||||
/* in gui.c */
|
||||
void ro_gui_copy_selection(gui_window* g);
|
||||
@ -103,6 +92,7 @@ void ro_gui_menus_init(void);
|
||||
void ro_gui_create_menu(wimp_menu* menu, int x, int y, gui_window* g);
|
||||
void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i);
|
||||
void ro_gui_menu_selection(wimp_selection* selection);
|
||||
void ro_gui_menu_warning(wimp_message_menu_warning *warning);
|
||||
|
||||
/* in dialog.c */
|
||||
void ro_gui_dialog_init(void);
|
||||
@ -113,21 +103,24 @@ bool ro_gui_dialog_keypress(wimp_key *key);
|
||||
void ro_gui_dialog_close(wimp_w close);
|
||||
void ro_gui_redraw_config_th(wimp_draw* redraw);
|
||||
void ro_gui_theme_menu_selection(char *theme);
|
||||
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text);
|
||||
char *ro_gui_get_icon_string(wimp_w w, wimp_i i);
|
||||
|
||||
/* in download.c */
|
||||
void ro_gui_download_init(void);
|
||||
void ro_download_window_close(struct gui_window *g);
|
||||
struct gui_window * ro_lookup_download_window_from_w(wimp_w window);
|
||||
void ro_download_window_click(struct gui_window *g, wimp_pointer *pointer);
|
||||
void ro_download_drag_end(wimp_dragged *drag);
|
||||
void ro_download_datasave_ack(wimp_message *message);
|
||||
|
||||
/* in mouseactions.c */
|
||||
void ro_gui_mouse_action(gui_window* g);
|
||||
|
||||
/* in textselection.c */
|
||||
extern struct ro_gui_drag_info current_drag;
|
||||
void ro_gui_start_selection(wimp_pointer *pointer, wimp_window_state *state,
|
||||
gui_window *g);
|
||||
void ro_gui_drag_end(wimp_dragged* drag);
|
||||
gui_window *g);
|
||||
void ro_gui_selection_drag_end(wimp_dragged *drag);
|
||||
|
||||
/* in 401login.c */
|
||||
#ifdef WITH_AUTH
|
||||
@ -160,6 +153,12 @@ void ro_gui_history_open(struct browser_window *bw,
|
||||
void ro_gui_history_redraw(wimp_draw *redraw);
|
||||
void ro_gui_history_click(wimp_pointer *pointer);
|
||||
|
||||
/* in save.c */
|
||||
void ro_gui_save_click(wimp_pointer *pointer);
|
||||
void ro_gui_drag_icon(wimp_pointer *pointer);
|
||||
void ro_gui_save_drag_end(wimp_dragged *drag);
|
||||
void ro_gui_save_datasave_ack(wimp_message *message);
|
||||
|
||||
/* icon numbers */
|
||||
#define ICON_TOOLBAR_THROBBER 1
|
||||
#define ICON_TOOLBAR_URL 2
|
||||
@ -232,4 +231,9 @@ void ro_gui_history_click(wimp_pointer *pointer);
|
||||
#define ICON_ZOOM_CANCEL 9
|
||||
#define ICON_ZOOM_OK 10
|
||||
|
||||
#define ICON_SAVE_ICON 0
|
||||
#define ICON_SAVE_PATH 1
|
||||
#define ICON_SAVE_OK 2
|
||||
#define ICON_SAVE_CANCEL 3
|
||||
|
||||
#endif
|
||||
|
@ -48,12 +48,20 @@ wimp_menu *iconbar_menu = (wimp_menu *) & (wimp_MENU(4)) {
|
||||
int iconbar_menu_height = 4 * 44;
|
||||
|
||||
/* browser window menu structure - based on Style Guide */
|
||||
static wimp_MENU(1) export_menu = {
|
||||
{ "ExportAs" }, 7,2,7,0, 200, 44, 0,
|
||||
{
|
||||
{ wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Draw" } }
|
||||
}
|
||||
};
|
||||
static wimp_menu *browser_export_menu = (wimp_menu *) &export_menu;
|
||||
|
||||
static wimp_MENU(4) page_menu = {
|
||||
{ "Page" }, 7,2,7,0, 200, 44, 0,
|
||||
{
|
||||
{ 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Info" } },
|
||||
{ 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Save" } },
|
||||
{ 0, (wimp_menu *) 1, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Export" } },
|
||||
{ wimp_MENU_GIVE_WARNING, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Save" } },
|
||||
{ 0, (wimp_menu *) &export_menu, DEFAULT_FLAGS, { "Export" } },
|
||||
{ wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Print" } }
|
||||
}
|
||||
};
|
||||
@ -109,12 +117,14 @@ void ro_gui_menus_init(void)
|
||||
translate_menu(iconbar_menu);
|
||||
translate_menu(browser_menu);
|
||||
translate_menu(browser_page_menu);
|
||||
translate_menu(browser_export_menu);
|
||||
translate_menu(browser_selection_menu);
|
||||
translate_menu(browser_navigate_menu);
|
||||
translate_menu(browser_view_menu);
|
||||
|
||||
iconbar_menu->entries[0].sub_menu = (wimp_menu *) dialog_info;
|
||||
browser_page_menu->entries[1].sub_menu = (wimp_menu *) dialog_saveas;
|
||||
browser_export_menu->entries[0].sub_menu = (wimp_menu *) dialog_saveas;
|
||||
browser_view_menu->entries[0].sub_menu = (wimp_menu *) dialog_zoom;
|
||||
}
|
||||
|
||||
@ -268,3 +278,42 @@ void ro_gui_menu_selection(wimp_selection *selection)
|
||||
ro_gui_create_menu(current_menu, current_menu_x, current_menu_y, current_gui);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle Message_MenuWarning by opening the save dialog.
|
||||
*/
|
||||
|
||||
void ro_gui_menu_warning(wimp_message_menu_warning *warning)
|
||||
{
|
||||
os_error *error;
|
||||
|
||||
if (warning->selection.items[0] != 0)
|
||||
return;
|
||||
|
||||
switch (warning->selection.items[2]) {
|
||||
case 0: /* Export as -> Draw */
|
||||
gui_current_save_type = GUI_SAVE_DRAW;
|
||||
ro_gui_set_icon_string(dialog_saveas,
|
||||
ICON_SAVE_ICON, "file_aff");
|
||||
ro_gui_set_icon_string(dialog_saveas,
|
||||
ICON_SAVE_PATH, "Webpage");
|
||||
break;
|
||||
|
||||
case -1:
|
||||
default: /* Save */
|
||||
gui_current_save_type = GUI_SAVE_SOURCE;
|
||||
ro_gui_set_icon_string(dialog_saveas,
|
||||
ICON_SAVE_ICON, "file_faf");
|
||||
ro_gui_set_icon_string(dialog_saveas,
|
||||
ICON_SAVE_PATH, "Source");
|
||||
break;
|
||||
}
|
||||
|
||||
error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas,
|
||||
warning->pos.x, warning->pos.y);
|
||||
if (error) {
|
||||
LOG(("0x%x: %s\n", error->errnum, error->errmess));
|
||||
warn_user(error->errmess);
|
||||
}
|
||||
}
|
||||
|
126
riscos/save.c
Normal file
126
riscos/save.c
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 2004 James Bursa <bursa@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* Save dialog and drag and drop saving (implementation).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "oslib/dragasprite.h"
|
||||
#include "oslib/wimp.h"
|
||||
#include "netsurf/riscos/gui.h"
|
||||
#include "netsurf/riscos/save_draw.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/messages.h"
|
||||
#include "netsurf/utils/utils.h"
|
||||
|
||||
gui_save_type gui_current_save_type;
|
||||
|
||||
|
||||
/**
|
||||
* Handle clicks in the save dialog.
|
||||
*/
|
||||
|
||||
void ro_gui_save_click(wimp_pointer *pointer)
|
||||
{
|
||||
switch (pointer->i) {
|
||||
case ICON_SAVE_ICON:
|
||||
if (pointer->buttons == wimp_DRAG_SELECT) {
|
||||
gui_current_drag_type = GUI_DRAG_SAVE;
|
||||
ro_gui_drag_icon(pointer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start drag of icon under the pointer.
|
||||
*/
|
||||
|
||||
void ro_gui_drag_icon(wimp_pointer *pointer)
|
||||
{
|
||||
char *sprite;
|
||||
os_box box = { pointer->pos.x - 34, pointer->pos.y - 34,
|
||||
pointer->pos.x + 34, pointer->pos.y + 34 };
|
||||
os_error *error;
|
||||
|
||||
if (pointer->i == -1)
|
||||
return;
|
||||
|
||||
sprite = ro_gui_get_icon_string(pointer->w, pointer->i);
|
||||
|
||||
error = xdragasprite_start(dragasprite_HPOS_CENTRE |
|
||||
dragasprite_VPOS_CENTRE |
|
||||
dragasprite_BOUND_POINTER |
|
||||
dragasprite_DROP_SHADOW,
|
||||
(osspriteop_area *) 1, sprite, &box, 0);
|
||||
if (error) {
|
||||
LOG(("0x%x: %s", error->errnum, error->errmess));
|
||||
warn_user(error->errmess);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle User_Drag_Box event for a drag from the save dialog.
|
||||
*/
|
||||
|
||||
void ro_gui_save_drag_end(wimp_dragged *drag)
|
||||
{
|
||||
wimp_pointer pointer;
|
||||
wimp_message message;
|
||||
|
||||
wimp_get_pointer_info(&pointer);
|
||||
|
||||
message.your_ref = 0;
|
||||
message.action = message_DATA_SAVE;
|
||||
message.data.data_xfer.w = pointer.w;
|
||||
message.data.data_xfer.i = pointer.i;
|
||||
message.data.data_xfer.pos.x = pointer.pos.x;
|
||||
message.data.data_xfer.pos.y = pointer.pos.y;
|
||||
message.data.data_xfer.est_size = 1000;
|
||||
message.data.data_xfer.file_type = 0xfaf;
|
||||
if (gui_current_save_type == GUI_SAVE_DRAW)
|
||||
message.data.data_xfer.file_type = 0xaff;
|
||||
strncpy(message.data.data_xfer.file_name,
|
||||
ro_gui_get_icon_string(dialog_saveas, ICON_SAVE_PATH),
|
||||
212);
|
||||
message.size = 44 + ((strlen(message.data.data_xfer.file_name) + 4) &
|
||||
(~3u));
|
||||
|
||||
wimp_send_message_to_window(wimp_USER_MESSAGE, &message,
|
||||
pointer.w, pointer.i);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle Message_DataSaveAck for a drag from the save dialog.
|
||||
*/
|
||||
|
||||
void ro_gui_save_datasave_ack(wimp_message *message)
|
||||
{
|
||||
char *path = message->data.data_xfer.file_name;
|
||||
|
||||
ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, path);
|
||||
|
||||
switch (gui_current_save_type) {
|
||||
case GUI_SAVE_SOURCE:
|
||||
warn_user("Not implemented yet!");
|
||||
return;
|
||||
|
||||
case GUI_SAVE_DRAW:
|
||||
if (!current_gui->data.browser.bw->current_content)
|
||||
return;
|
||||
save_as_draw(current_gui->data.browser.bw->
|
||||
current_content, path);
|
||||
break;
|
||||
}
|
||||
|
||||
wimp_create_menu(wimp_CLOSE_MENU, 0, 0);
|
||||
}
|
@ -51,8 +51,8 @@ static void add_circle(struct content *content, struct box *box,
|
||||
unsigned long cbc, long x, long y);
|
||||
|
||||
/** \todo this will probably want to take a filename/path too... */
|
||||
void save_as_draw(struct content *c) {
|
||||
|
||||
void save_as_draw(struct content *c, char *path)
|
||||
{
|
||||
struct box *box;
|
||||
int temp;
|
||||
unsigned long bc;
|
||||
@ -94,7 +94,7 @@ void save_as_draw(struct content *c) {
|
||||
/* right, traverse the tree and grab the contents */
|
||||
add_objects(c, box, bc, 0, A4PAGEHEIGHT*512);
|
||||
|
||||
xosfile_save_stamped("<NetSurf$Dir>.draw", 0xaff, (byte*)d, (byte*)d+length);
|
||||
xosfile_save_stamped(path, 0xaff, (byte*)d, (byte*)d+length);
|
||||
|
||||
xfree(d);
|
||||
|
||||
|
@ -10,6 +10,6 @@
|
||||
|
||||
struct content;
|
||||
|
||||
void save_as_draw(struct content *c);
|
||||
void save_as_draw(struct content *c, char *path);
|
||||
|
||||
#endif
|
||||
|
@ -12,51 +12,34 @@
|
||||
#include "netsurf/utils/utils.h"
|
||||
|
||||
|
||||
struct ro_gui_drag_info current_drag;
|
||||
|
||||
static void ro_gui_drag_box(wimp_drag* drag, struct ro_gui_drag_info* drag_info);
|
||||
|
||||
|
||||
void ro_gui_start_selection(wimp_pointer *pointer, wimp_window_state *state,
|
||||
gui_window *g) {
|
||||
gui_window *g)
|
||||
{
|
||||
wimp_drag drag;
|
||||
|
||||
wimp_drag drag;
|
||||
struct ro_gui_drag_info drag_info;
|
||||
|
||||
drag.type = wimp_DRAG_USER_POINT;
|
||||
drag.initial.x0 = pointer->pos.x;
|
||||
drag.initial.y0 = pointer->pos.y;
|
||||
drag.initial.x1 = pointer->pos.x;
|
||||
drag.initial.y1 = pointer->pos.y;
|
||||
drag.bbox.x0 = state->visible.x0;
|
||||
drag.bbox.y0 = state->visible.y0;
|
||||
drag.bbox.x1 = state->visible.x1;
|
||||
drag.bbox.y1 = state->visible.y1;
|
||||
drag_info.type = draginfo_BROWSER_TEXT_SELECTION;
|
||||
drag_info.data.selection.gui = g;
|
||||
ro_gui_drag_box(&drag, &drag_info);
|
||||
gui_current_drag_type = GUI_DRAG_SELECTION;
|
||||
current_gui = g;
|
||||
|
||||
drag.type = wimp_DRAG_USER_POINT;
|
||||
drag.initial.x0 = pointer->pos.x;
|
||||
drag.initial.y0 = pointer->pos.y;
|
||||
drag.initial.x1 = pointer->pos.x;
|
||||
drag.initial.y1 = pointer->pos.y;
|
||||
drag.bbox.x0 = state->visible.x0;
|
||||
drag.bbox.y0 = state->visible.y0;
|
||||
drag.bbox.x1 = state->visible.x1;
|
||||
drag.bbox.y1 = state->visible.y1;
|
||||
wimp_drag_box(&drag);
|
||||
}
|
||||
|
||||
void ro_gui_drag_box(wimp_drag* drag, struct ro_gui_drag_info* drag_info)
|
||||
{
|
||||
wimp_drag_box(drag);
|
||||
|
||||
if (drag_info != NULL)
|
||||
memcpy(¤t_drag, drag_info, sizeof(struct ro_gui_drag_info));
|
||||
else
|
||||
current_drag.type = draginfo_NONE;
|
||||
}
|
||||
|
||||
void ro_gui_drag_end(wimp_dragged* drag)
|
||||
void ro_gui_selection_drag_end(wimp_dragged *drag)
|
||||
{
|
||||
if (current_drag.type == draginfo_BROWSER_TEXT_SELECTION)
|
||||
{
|
||||
struct browser_action msg;
|
||||
int final_x0, final_y0;
|
||||
wimp_window_state state;
|
||||
|
||||
state.w = current_drag.data.selection.gui->window;
|
||||
state.w = current_gui->window;
|
||||
wimp_get_window_state(&state);
|
||||
|
||||
final_x0 = window_x_units(drag->final.x0, &state) / 2;
|
||||
@ -65,81 +48,19 @@ void ro_gui_drag_end(wimp_dragged* drag)
|
||||
msg.data.mouse.x = final_x0;
|
||||
msg.data.mouse.y = final_y0;
|
||||
msg.type = act_ALTER_SELECTION;
|
||||
browser_window_action(current_drag.data.selection.gui->data.browser.bw, &msg);
|
||||
browser_window_action(current_gui->data.browser.bw, &msg);
|
||||
|
||||
if (box_position_eq(&(current_drag.data.selection.gui->data.browser.bw->current_content->data.html.text_selection.start),
|
||||
&(current_drag.data.selection.gui->data.browser.bw->current_content->data.html.text_selection.end)))
|
||||
if (box_position_eq(&(current_gui->data.browser.bw->current_content->data.html.text_selection.start),
|
||||
&(current_gui->data.browser.bw->current_content->data.html.text_selection.end)))
|
||||
{
|
||||
msg.type = act_CLEAR_SELECTION;
|
||||
browser_window_action(current_drag.data.selection.gui->data.browser.bw, &msg);
|
||||
browser_window_action(current_gui->data.browser.bw, &msg);
|
||||
}
|
||||
current_drag.data.selection.gui->drag_status = drag_NONE;
|
||||
current_drag.data.selection.gui->data.browser.bw->current_content->data.html.text_selection.altering = alter_UNKNOWN;
|
||||
|
||||
current_drag.type = draginfo_NONE;
|
||||
}
|
||||
|
||||
else if (current_drag.type == draginfo_DOWNLOAD_SAVE)
|
||||
{
|
||||
wimp_pointer *pointer_dropped;
|
||||
wimp_message *send_message;
|
||||
//wimp_icon_state *icon_state;
|
||||
|
||||
LOG(("Download icon dropped"));
|
||||
|
||||
pointer_dropped = xcalloc(1, sizeof(*pointer_dropped));
|
||||
wimp_get_pointer_info(pointer_dropped);
|
||||
|
||||
//Send message, saying "please save this data!"
|
||||
send_message = xcalloc(1, sizeof(*send_message));
|
||||
|
||||
send_message->size = sizeof(*send_message);
|
||||
send_message->your_ref = 0;
|
||||
send_message->action = message_DATA_SAVE;
|
||||
send_message->data.data_xfer.w = pointer_dropped->w;
|
||||
send_message->data.data_xfer.i = pointer_dropped->i;
|
||||
|
||||
send_message->data.data_xfer.pos.x = pointer_dropped->pos.x;
|
||||
send_message->data.data_xfer.pos.y = pointer_dropped->pos.y;
|
||||
|
||||
send_message->data.data_xfer.est_size = (int)
|
||||
current_drag.data.download.gui->data.download.content->data.other.length;
|
||||
|
||||
send_message->data.data_xfer.file_type =
|
||||
current_drag.data.download.gui->data.download.file_type;
|
||||
|
||||
/*icon_state = xcalloc(1, sizeof(icon_state));
|
||||
|
||||
icon_state->w = pointer_dropped->w;
|
||||
icon_state->i = ICON_DOWNLOAD_PATH;
|
||||
wimp_get_icon_state(icon_state);
|
||||
|
||||
LOG(("Getting indirected text"));
|
||||
|
||||
strncpy(send_message->data.data_xfer.file_name,
|
||||
icon_state->icon.data.indirected_text.text,
|
||||
icon_state->icon.data.indirected_text.size);*/
|
||||
|
||||
strcpy(send_message->data.data_xfer.file_name,
|
||||
current_drag.data.download.gui->data.download.path);
|
||||
|
||||
LOG(("Sending message to window owner, filename = %s, length = %d",
|
||||
send_message->data.data_xfer.file_name,
|
||||
send_message->data.data_xfer.est_size));
|
||||
|
||||
LOG(("Sending....."));
|
||||
|
||||
wimp_send_message_to_window(wimp_USER_MESSAGE, send_message,
|
||||
pointer_dropped->w, pointer_dropped->i);
|
||||
|
||||
LOG(("Sent."));
|
||||
|
||||
//xfree(icon_state);
|
||||
xfree(send_message);
|
||||
xfree(pointer_dropped);
|
||||
}
|
||||
current_gui->drag_status = drag_NONE;
|
||||
current_gui->data.browser.bw->current_content->data.html.text_selection.altering = alter_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
void ro_gui_copy_selection(gui_window* g)
|
||||
{
|
||||
if (g->type == GUI_BROWSER_WINDOW)
|
||||
|
@ -618,7 +618,7 @@ void ro_gui_window_click(gui_window* g, wimp_pointer* pointer)
|
||||
|
||||
if (pointer->buttons == wimp_CLICK_ADJUST && g->data.browser.bw->current_content->data.html.text_selection.selected == 1)
|
||||
{
|
||||
current_drag.data.selection.gui->data.browser.bw->current_content->data.html.text_selection.altering = alter_UNKNOWN;
|
||||
current_gui->data.browser.bw->current_content->data.html.text_selection.altering = alter_UNKNOWN;
|
||||
}
|
||||
|
||||
if (pointer->buttons == wimp_CLICK_SELECT
|
||||
@ -727,7 +727,7 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar)
|
||||
#endif
|
||||
#ifdef WITH_DRAW_EXPORT
|
||||
case wimp_KEY_SHIFT + wimp_KEY_CONTROL + wimp_KEY_F3:
|
||||
save_as_draw(g->data.browser.bw->current_content);
|
||||
/* save_as_draw(g->data.browser.bw->current_content); */
|
||||
return true;
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user