2004-02-26 03:44:42 +03: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 2004 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Save dialog and drag and drop saving (implementation).
|
|
|
|
*/
|
|
|
|
|
2004-03-27 21:47:56 +03:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
2004-02-26 03:44:42 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/dragasprite.h"
|
2004-03-27 21:47:56 +03:00
|
|
|
#include "oslib/osfile.h"
|
2004-02-26 03:44:42 +03:00
|
|
|
#include "oslib/wimp.h"
|
2004-03-25 03:31:45 +03:00
|
|
|
#include "netsurf/desktop/save_text.h"
|
2004-02-26 03:44:42 +03:00
|
|
|
#include "netsurf/riscos/gui.h"
|
2004-03-27 21:47:56 +03:00
|
|
|
#include "netsurf/riscos/save_complete.h"
|
2004-02-26 03:44:42 +03:00
|
|
|
#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;
|
|
|
|
|
2004-03-27 21:47:56 +03:00
|
|
|
void ro_gui_save_complete(struct content *c, char *path);
|
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2004-03-27 21:47:56 +03:00
|
|
|
LOG(("xdragasprite_start: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
2004-02-26 03:44:42 +03:00
|
|
|
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)
|
|
|
|
{
|
2004-03-27 21:47:56 +03:00
|
|
|
char *name;
|
|
|
|
char *dot;
|
2004-02-26 03:44:42 +03:00
|
|
|
wimp_pointer pointer;
|
|
|
|
wimp_message message;
|
|
|
|
|
|
|
|
wimp_get_pointer_info(&pointer);
|
|
|
|
|
2004-03-27 21:47:56 +03:00
|
|
|
name = ro_gui_get_icon_string(dialog_saveas, ICON_SAVE_PATH);
|
|
|
|
dot = strrchr(name, '.');
|
|
|
|
if (dot)
|
|
|
|
name = dot + 1;
|
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
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;
|
2004-03-27 21:47:56 +03:00
|
|
|
if (gui_current_save_type == GUI_SAVE_COMPLETE) {
|
|
|
|
message.data.data_xfer.file_type = 0x2000;
|
|
|
|
if (name[0] != '!') {
|
|
|
|
message.data.data_xfer.file_name[0] = '!';
|
|
|
|
strncpy(message.data.data_xfer.file_name + 1, name,
|
|
|
|
211);
|
|
|
|
} else {
|
|
|
|
strncpy(message.data.data_xfer.file_name, name, 212);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
strncpy(message.data.data_xfer.file_name, name, 212);
|
|
|
|
message.data.data_xfer.file_name[211] = 0;
|
2004-02-26 03:44:42 +03:00
|
|
|
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;
|
2004-03-11 05:19:14 +03:00
|
|
|
struct content *c = current_gui->data.browser.bw->current_content;
|
2004-03-27 21:47:56 +03:00
|
|
|
os_error *error;
|
2004-02-26 03:44:42 +03:00
|
|
|
|
|
|
|
ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, path);
|
|
|
|
|
|
|
|
switch (gui_current_save_type) {
|
|
|
|
case GUI_SAVE_SOURCE:
|
2004-03-11 05:19:14 +03:00
|
|
|
if (!c)
|
2004-03-06 15:34:47 +03:00
|
|
|
return;
|
2004-03-27 21:47:56 +03:00
|
|
|
error = xosfile_save_stamped(path,
|
|
|
|
ro_content_filetype(c),
|
2004-03-11 05:19:14 +03:00
|
|
|
c->source_data,
|
|
|
|
c->source_data + c->source_size);
|
2004-03-27 21:47:56 +03:00
|
|
|
if (error) {
|
|
|
|
LOG(("xosfile_save_stamped: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user(error->errmess);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_SAVE_COMPLETE:
|
|
|
|
if (!c)
|
|
|
|
return;
|
|
|
|
ro_gui_save_complete(c, path);
|
2004-03-06 15:34:47 +03:00
|
|
|
break;
|
2004-02-26 03:44:42 +03:00
|
|
|
|
|
|
|
case GUI_SAVE_DRAW:
|
2004-03-11 05:19:14 +03:00
|
|
|
if (!c)
|
2004-02-26 03:44:42 +03:00
|
|
|
return;
|
2004-03-11 05:19:14 +03:00
|
|
|
save_as_draw(c, path);
|
2004-02-26 03:44:42 +03:00
|
|
|
break;
|
2004-03-25 02:51:08 +03:00
|
|
|
|
|
|
|
case GUI_SAVE_TEXT:
|
|
|
|
if (!c)
|
|
|
|
return;
|
|
|
|
save_as_text(c, path);
|
|
|
|
break;
|
2004-02-26 03:44:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wimp_create_menu(wimp_CLOSE_MENU, 0, 0);
|
|
|
|
}
|
2004-03-27 21:47:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare an application directory and save_complete() to it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_save_complete(struct content *c, char *path)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
FILE *fp;
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
error = xosfile_create_dir(path, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosfile_create_dir: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user(error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, sizeof buf, "%s.!Run", path);
|
|
|
|
fp = fopen(buf, "w");
|
|
|
|
if (!fp) {
|
|
|
|
LOG(("fopen(): errno = %i", errno));
|
|
|
|
warn_user(strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(fp, "Filer_Run <Obey$Dir>.index\n");
|
|
|
|
fclose(fp);
|
|
|
|
error = xosfile_set_type(buf, 0xfeb);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosfile_set_type: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user(error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
save_complete(c, path);
|
|
|
|
}
|