summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2004-05-03 22:05:40 +0000
committerJames Bursa <james@netsurf-browser.org>2004-05-03 22:05:40 +0000
commit8da6079f6f777e509c84f552b6a31f02698599b0 (patch)
tree728d29ae023e6402502ab7cec2bbc2209995d78a /riscos
parent24c57d3215f7e906ee312f19c6b1a870e984e765 (diff)
downloadnetsurf-8da6079f6f777e509c84f552b6a31f02698599b0.tar.gz
netsurf-8da6079f6f777e509c84f552b6a31f02698599b0.tar.bz2
[project @ 2004-05-03 22:05:40 by bursa]
Implement dragging files into <input type="file" ...>. svn path=/import/netsurf/; revision=821
Diffstat (limited to 'riscos')
-rw-r--r--riscos/gui.c10
-rw-r--r--riscos/gui.h1
-rw-r--r--riscos/htmlredraw.c45
-rw-r--r--riscos/window.c71
4 files changed, 123 insertions, 4 deletions
diff --git a/riscos/gui.c b/riscos/gui.c
index 0952c7b65..6888e234c 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -989,11 +989,13 @@ void ro_msg_datasave(wimp_message* block)
void ro_msg_dataload(wimp_message *message)
{
char *url = 0;
- gui_window *gui = 0;
+ gui_window *gui;
- if (message->data.data_xfer.w != wimp_ICON_BAR &&
- (gui = ro_lookup_gui_from_w(message->data.data_xfer.w)) == NULL) {
- return;
+ gui = ro_lookup_gui_from_w(message->data.data_xfer.w);
+
+ if (gui) {
+ if (ro_gui_window_dataload(gui, message))
+ return;
}
if (message->data.data_xfer.file_type != 0xfaf &&
diff --git a/riscos/gui.h b/riscos/gui.h
index c11233551..678057d9f 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -147,6 +147,7 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar);
void ro_gui_scroll_request(wimp_scroll *scroll);
int window_x_units(int x, wimp_window_state *state);
int window_y_units(int y, wimp_window_state *state);
+bool ro_gui_window_dataload(gui_window *g, wimp_message *message);
/* in history.c */
void ro_gui_history_init(void);
diff --git a/riscos/htmlredraw.c b/riscos/htmlredraw.c
index 363025609..6c61c0c94 100644
--- a/riscos/htmlredraw.c
+++ b/riscos/htmlredraw.c
@@ -18,6 +18,7 @@
#include "netsurf/render/html.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/utils/log.h"
+#include "netsurf/utils/messages.h"
#include "netsurf/utils/utils.h"
@@ -42,6 +43,8 @@ static void html_redraw_checkbox(int x, int y, int width, int height,
bool selected);
static void html_redraw_radio(int x, int y, int width, int height,
bool selected);
+static void html_redraw_file(int x, int y, int width, int height,
+ struct box *box, float scale);
bool gui_redraw_debug = false;
@@ -231,6 +234,13 @@ void html_redraw_box(struct content *content, struct box * box,
width, height,
box->gadget->data.radio.selected);
+ } else if (box->gadget && box->gadget->type == GADGET_FILE) {
+ colourtrans_set_font_colours(box->font->handle,
+ current_background_color << 8,
+ box->style->color << 8, 14, 0, 0, 0);
+ html_redraw_file(x + padding_left, y - padding_top,
+ width, height, box, scale);
+
} else if (box->text && box->font) {
if (content->data.html.text_selection.selected == 1) {
@@ -499,3 +509,38 @@ void html_redraw_radio(int x, int y, int width, int height,
html_redraw_circle(x + width * 0.5, y - height * 0.5,
width * 0.3 - 1, os_COLOUR_RED);
}
+
+
+/**
+ * Plot a file upload input.
+ */
+
+void html_redraw_file(int x, int y, int width, int height,
+ struct box *box, float scale)
+{
+ int text_width;
+ const char *text;
+ const char *sprite;
+
+ if (box->gadget->value) {
+ text = box->gadget->value;
+ sprite = "file_fff";
+ } else {
+ text = messages_get("Form_Drop");
+ sprite = "drophere";
+ }
+
+ text_width = font_width(box->font, text, strlen(text)) * 2 * scale;
+ if (width < text_width + 8)
+ x = x + width - text_width - 4;
+ else
+ x = x + 4;
+
+ font_paint(box->font->handle, text,
+ font_OS_UNITS | font_GIVEN_FONT |
+ font_KERN | font_GIVEN_TRFM,
+ x, y - height * 0.75, 0, &trfm, 0);
+
+/* xwimpspriteop_put_sprite_user_coords(sprite, x + 4, */
+/* y - height / 2 - 17, os_ACTION_OVERWRITE); */
+}
diff --git a/riscos/window.c b/riscos/window.c
index 9a245028a..cbe37e166 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -27,6 +27,7 @@
#include "netsurf/riscos/save_draw.h"
#include "netsurf/riscos/theme.h"
#include "netsurf/riscos/thumbnail.h"
+#include "netsurf/render/form.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/url.h"
#include "netsurf/utils/utils.h"
@@ -1003,3 +1004,73 @@ int window_y_units(int y, wimp_window_state *state)
{
return y - (state->visible.y1 - state->yscroll);
}
+
+
+/**
+ * Handle Message_DataLoad (file dragged in) for a window.
+ *
+ * \param g window
+ * \param message Message_DataLoad block
+ * \return true if the load was processed
+ *
+ * If the file was dragged into a form file input, it is used as the value.
+ */
+
+bool ro_gui_window_dataload(gui_window *g, wimp_message *message)
+{
+ struct browser_window *bw = g->data.browser.bw;
+ struct box_selection *click_boxes = 0;
+ int x, y;
+ int i;
+ int found = 0;
+ int plot_index = 0;
+ wimp_window_state state;
+
+ /* HTML content only. */
+ if (!bw->current_content || bw->current_content->type != CONTENT_HTML)
+ return false;
+
+ /* Ignore directories etc. */
+ if (0x1000 <= message->data.data_xfer.file_type)
+ return false;
+
+ /* Search for a file input at the drop point. */
+ state.w = message->data.data_xfer.w;
+ wimp_get_window_state(&state);
+ x = window_x_units(message->data.data_xfer.pos.x, &state) / 2;
+ y = -window_y_units(message->data.data_xfer.pos.y, &state) / 2;
+
+ box_under_area(bw->current_content,
+ bw->current_content->data.html.layout->children,
+ x, y, 0, 0, &click_boxes, &found, &plot_index);
+ if (found == 0)
+ return false;
+ for (i = 0; i != found; i++) {
+ if (click_boxes[i].box->gadget &&
+ click_boxes[i].box->gadget->type ==
+ GADGET_FILE)
+ break;
+ }
+ if (i == found) {
+ free(click_boxes);
+ return false;
+ }
+
+ /* Found: update form input. */
+ free(click_boxes[i].box->gadget->value);
+ click_boxes[i].box->gadget->value =
+ strdup(message->data.data_xfer.file_name);
+
+ /* Redraw box. */
+ box_coords(click_boxes[i].box, &x, &y);
+ gui_window_redraw(bw->window, x, y,
+ x + click_boxes[i].box->width,
+ y + click_boxes[i].box->height);
+
+ /* send DataLoadAck */
+ message->action = message_DATA_LOAD_ACK;
+ message->your_ref = message->my_ref;
+ wimp_send_message(wimp_USER_MESSAGE, message, message->sender);
+
+ return true;
+}