[project @ 2003-10-05 23:30:21 by rob]

Implemented download window interface, and modified ro_drag_info struct

svn path=/import/netsurf/; revision=345
This commit is contained in:
Rob Jackson 2003-10-05 23:30:21 +00:00
parent f528562103
commit 0b5bea4c19
6 changed files with 260 additions and 7 deletions

Binary file not shown.

View File

@ -896,7 +896,7 @@ void browser_window_textarea_callback(struct browser_window *bw, char key, void
dy = -textarea->children->y;
for (ic = textarea->children; ic; ic = ic->next)
ic->y += dy;
pixel_offset = font_width(text_box->font, text_box->text, char_offset);
textarea->gadget->caret_inline_container = inline_container;

View File

@ -94,6 +94,8 @@ gui_window *gui_create_download_window(struct content *content)
g->data.download.window = wimp_create_window(download_template);
ro_gui_dialog_open(g->data.download.window);
g->data.download.download_status = download_INCOMPLETE;
g->next = window_list;
window_list = g;
return g;
@ -156,6 +158,8 @@ void gui_download_window_error(gui_window *g, const char *error)
ICON_DOWNLOAD_ICON, wimp_ICON_SHADED, 0);
wimp_set_icon_state(g->data.download.window,
ICON_DOWNLOAD_PATH, wimp_ICON_SHADED, 0);
g->data.download.download_status = download_ERROR;
}
@ -169,5 +173,60 @@ void gui_download_window_done(gui_window *g)
g->data.download.content->data.other.length);
wimp_set_icon_state(g->data.download.window,
ICON_DOWNLOAD_STATUS, 0, 0);
// clear shaded path and icon icons
wimp_set_icon_state(g->data.download.window,
ICON_DOWNLOAD_ICON, 0, wimp_ICON_SHADED);
wimp_set_icon_state(g->data.download.window,
ICON_DOWNLOAD_PATH, 0, wimp_ICON_SHADED);
g->data.download.download_status = download_COMPLETE;
}
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);
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;
}
}
struct gui_window * ro_lookup_download_window_from_w(wimp_w window)
{
gui_window* g;
for (g = window_list; g != NULL; g = g->next)
{
if (g->type == GUI_DOWNLOAD_WINDOW)
{
if (g->data.browser.window == window)
{
return g;
}
}
}
return NULL;
}
void ro_download_window_close(struct gui_window *g)
{
// free contexts etc???
wimp_close_window(g->data.download.window);
}

View File

@ -64,7 +64,9 @@ static void ro_gui_poll_queue(wimp_event_no event, wimp_block* block);
static void ro_gui_keypress(wimp_key* key);
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 void ro_gui_screen_size(int *width, int *height);
int ro_save_data(void *data, unsigned long length, char *file_name, bits file_type);
@ -79,8 +81,9 @@ ro_theme* current_theme = NULL;
const char* BROWSER_VALIDATION = "\0";
const char* task_name = "NetSurf";
const wimp_MESSAGE_LIST(22) task_messages = {
const wimp_MESSAGE_LIST(23) task_messages = {
{message_DATA_SAVE,
message_DATA_SAVE_ACK,
message_DATA_LOAD,
message_URI_PROCESS,
message_PLUG_IN_OPENING,
@ -949,6 +952,10 @@ void gui_multitask(void)
ro_msg_datasave(&(block.message));
break;
case message_DATA_SAVE_ACK :
ro_msg_datasave_ack(&(block.message));
break;
case message_DATA_LOAD :
ro_msg_dataload(&(block.message));
break;
@ -1175,7 +1182,14 @@ void gui_poll(void)
ro_gui_toolbar_click(g, &(block.pointer));
}
else
ro_gui_dialog_click(&(block.pointer));
{
g = ro_lookup_download_window_from_w(block.pointer.w);
if (g != NULL)
{
ro_download_window_click(g, &(block.pointer));
}
else ro_gui_dialog_click(&(block.pointer));
}
}
break;
@ -1209,6 +1223,10 @@ void gui_poll(void)
ro_msg_datasave(&(block.message));
break;
case message_DATA_SAVE_ACK :
ro_msg_datasave_ack(&(block.message));
break;
case message_DATA_LOAD :
ro_msg_dataload(&(block.message));
break;
@ -1245,12 +1263,13 @@ void gui_poll(void)
}
break;
}
}
} while (finished == 0);
return;
}
void gui_window_start_throbber(gui_window* g)
void gui_window_start_throbber(struct gui_window* g)
{
g->throbtime = (float) (clock() + 0) / CLOCKS_PER_SEC; /* workaround compiler warning */
g->throbber = 0;
@ -1459,3 +1478,103 @@ void ro_gui_open_help_page (void)
0,0,-1, (int) strlen(bw->window->url) - 1);
}
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->i;
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);
}
void ro_msg_datasave_ack(wimp_message *message)
{
int save_status = 0;
LOG(("ACK Message: filename = %s", message->data.data_xfer.file_name));
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 = (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;
}

View File

@ -26,7 +26,6 @@ extern struct gui_gadget *current_gadget;
extern const char *HOME_URL;
extern gui_window *window_list;
struct gui_window
{
gui_window_type type;
@ -46,6 +45,11 @@ struct gui_window
bits file_type;
char sprite_name[20];
char path[256];
enum {
download_COMPLETE,
download_INCOMPLETE,
download_ERROR
} download_status;
} download;
} data;
@ -63,13 +67,18 @@ struct gui_window
struct ro_gui_drag_info
{
enum { draginfo_UNKNOWN, draginfo_NONE, draginfo_BROWSER_TEXT_SELECTION } type;
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;
};
@ -98,6 +107,9 @@ void ro_gui_theme_menu_selection(char *theme);
/* 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);
/* in mouseactions.c */
void ro_gui_mouse_action(gui_window* g);

View File

@ -7,6 +7,9 @@
#include "oslib/wimp.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
struct ro_gui_drag_info current_drag;
@ -71,9 +74,69 @@ void ro_gui_drag_end(wimp_dragged* drag)
}
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;
}
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 = %lu",
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);
}
}
void ro_gui_copy_selection(gui_window* g)