From 1bd4a34a271e4f839298f56d8e45f02dfa9d378b Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 14:39:08 +0000 Subject: Remove asserts for default cases from all content message handlers; this is laborious and is no longer useful for catching bugs. --- desktop/browser.c | 2 +- desktop/searchweb.c | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'desktop') diff --git a/desktop/browser.c b/desktop/browser.c index d159a5599..83b06bac5 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1556,7 +1556,7 @@ static nserror browser_window_callback(hlcache_handle *c, break; default: - assert(0); + break; } return NSERROR_OK; diff --git a/desktop/searchweb.c b/desktop/searchweb.c index 87e3e21f1..4c050d97a 100644 --- a/desktop/searchweb.c +++ b/desktop/searchweb.c @@ -304,9 +304,6 @@ nserror search_web_ico_callback(hlcache_handle *ico, const hlcache_event *event, void *pw) { switch (event->type) { - case CONTENT_MSG_LOADING: - case CONTENT_MSG_READY: - break; case CONTENT_MSG_DONE: LOG(("got favicon '%s'", nsurl_access(hlcache_handle_get_url(ico)))); @@ -322,11 +319,8 @@ nserror search_web_ico_callback(hlcache_handle *ico, search_web_retrieve_ico(true); break; - case CONTENT_MSG_STATUS: - break; - default: - assert(0); + break; } return NSERROR_OK; -- cgit v1.2.3 From d8ad3b8e7893630d3866bc56c90f6f7556ab1740 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 16:01:03 +0000 Subject: Add new gui entry point for file open dialogue requests --- amiga/gui.c | 12 ++++++++++-- atari/gui.c | 7 +++++++ beos/gui.cpp | 8 ++++++++ cocoa/gui.m | 7 +++++++ desktop/gui.h | 3 ++- gtk/gui.c | 9 ++++++--- monkey/browser.c | 7 +++++++ riscos/gui.c | 8 ++++++++ 8 files changed, 55 insertions(+), 6 deletions(-) (limited to 'desktop') diff --git a/amiga/gui.c b/amiga/gui.c index 103d3a1e8..76185e949 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -4232,8 +4232,8 @@ static void ami_gui_window_update_box_deferred(struct gui_window *g, bool draw) static bool ami_gui_window_update_box_deferred_check(struct MinList *deferred_rects, const struct rect *new_rect) { - struct nsObject *node; - struct nsObject *nnode; +struct nsObject *node; +struct nsObject *nnode; struct rect *rect; if(IsMinListEmpty(deferred_rects)) return true; @@ -5137,3 +5137,11 @@ void ami_gui_splash_close(Object *win_obj) { if(win_obj) DisposeObject(win_obj); } + +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + diff --git a/atari/gui.c b/atari/gui.c index e52a6589c..badb4206c 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1098,6 +1098,13 @@ static void gui_init2(int argc, char** argv) toolbar_init(); } +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + /* #define WITH_DBG_LOGFILE 1 */ /** Entry point from OS. * diff --git a/beos/gui.cpp b/beos/gui.cpp index 204c11caf..6c9d1ed12 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1164,3 +1164,11 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } + +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + diff --git a/cocoa/gui.m b/cocoa/gui.m index b2ff01dc0..3804ad249 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -324,3 +324,10 @@ void gui_401login_open(nsurl *url, const char *realm, cb( false, cbpw ); } +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + diff --git a/desktop/gui.h b/desktop/gui.h index 9d35e1727..4bbf08718 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -116,7 +116,8 @@ void gui_drag_save_selection(struct gui_window *g, const char *selection); void gui_start_selection(struct gui_window *g); void gui_clear_selection(struct gui_window *g); - +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget); /** * Core asks front end for clipboard contents. diff --git a/gtk/gui.c b/gtk/gui.c index 649c4a239..0f815a7a2 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -681,9 +681,12 @@ void gui_quit(void) gtk_fetch_filetype_fin(); } - - - +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "plinth"); */ +} static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem, gpointer user_data) diff --git a/monkey/browser.c b/monkey/browser.c index 09ecf4b11..47fb07bc1 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -390,6 +390,13 @@ gui_window_save_link(struct gui_window *g, const char *url, g->win_num, url, title); } +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + /**** Handlers ****/ diff --git a/riscos/gui.c b/riscos/gui.c index bb1a318de..0c8ebecc7 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2423,3 +2423,11 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } + +void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, + struct form_control *gadget) +{ + LOG(("File open dialog rquest for %p/%p", bw, gadget)); + /* browser_window_set_gadget_filename(bw, gadget, "filename"); */ +} + -- cgit v1.2.3 From 0d7f1cfc93008add9a082c2c54de8427ac0f1786 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 16:04:35 +0000 Subject: Add infrastructure for calling front ends to set file gadget filenames via clicking in addition to drag-and-drop --- content/content.h | 7 +++++- desktop/browser.c | 17 ++++++++++++- desktop/browser.h | 3 +++ render/html.c | 70 ++++++++++++++++++++++++++++++---------------------- render/html.h | 2 ++ render/html_object.c | 1 + 6 files changed, 69 insertions(+), 31 deletions(-) (limited to 'desktop') diff --git a/content/content.h b/content/content.h index 467fa6055..91a6ae9df 100644 --- a/content/content.h +++ b/content/content.h @@ -83,7 +83,8 @@ typedef enum { CONTENT_MSG_POINTER, /**< Wants a specific mouse pointer set */ CONTENT_MSG_SELECTION, /**< A selection made or cleared */ CONTENT_MSG_CARET, /**< Caret movement / hiding */ - CONTENT_MSG_DRAG /**< A drag started or ended */ + CONTENT_MSG_DRAG, /**< A drag started or ended */ + CONTENT_MSG_GADGETCLICK/**< A gadget has been clicked on (mainly for file) */ } content_msg; /** RFC5988 metadata link */ @@ -190,6 +191,10 @@ union content_msg_data { } type; const struct rect *rect; } drag; + /** CONTENT_MSG_GADGETCLICK - User clicked on a form gadget */ + struct { + struct form_control *gadget; + } gadget_click; }; /** parameters to content redraw */ diff --git a/desktop/browser.c b/desktop/browser.c index 83b06bac5..3d279f727 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -661,6 +661,13 @@ bool browser_window_drop_file_at_point(struct browser_window *bw, return false; } +void browser_window_set_gadget_filename(struct browser_window *bw, + struct form_control *gadget, const char *fn) +{ + html_set_file_gadget_filename(bw->current_content, + gadget, fn); +} + /* exported interface, documented in browser.h */ void browser_window_debug_dump(struct browser_window *bw, FILE *f) { @@ -1162,7 +1169,7 @@ static void browser_window_convert_to_download(struct browser_window *bw, /** - * Callback for fetchcache() for browser window fetches. + * Callback handler for content event messages. */ static nserror browser_window_callback(hlcache_handle *c, @@ -1555,6 +1562,14 @@ static nserror browser_window_callback(hlcache_handle *c, event->data.selection.read_only); break; + case CONTENT_MSG_GADGETCLICK: + if (event->data.gadget_click.gadget->type == GADGET_FILE) { + gui_file_gadget_open(bw, c, + event->data.gadget_click.gadget); + } + + break; + default: break; } diff --git a/desktop/browser.h b/desktop/browser.h index ee55e72c4..0ca2e009b 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -173,6 +173,9 @@ bool browser_window_scroll_at_point(struct browser_window *bw, bool browser_window_drop_file_at_point(struct browser_window *bw, int x, int y, char *file); +void browser_window_set_gadget_filename(struct browser_window *bw, + struct form_control *gadget, const char *fn); + void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url, lwc_string *frag); diff --git a/render/html.c b/render/html.c index c1e831571..103dec14f 100644 --- a/render/html.c +++ b/render/html.c @@ -1729,6 +1729,46 @@ static void html__dom_user_data_handler(dom_node_operation operation, } } +static void html__set_file_gadget_filename(struct content *c, + struct form_control *gadget, const char *fn) +{ + utf8_convert_ret ret; + char *utf8_fn, *oldfile = NULL; + html_content *html = (html_content *)c; + struct box *file_box = gadget->box; + + ret = utf8_from_local_encoding(fn,0, &utf8_fn); + if (ret != UTF8_CONVERT_OK) { + assert(ret != UTF8_CONVERT_BADENC); + LOG(("utf8_from_local_encoding failed")); + /* Load was for us - just no memory */ + return; + } + + form_gadget_update_value(html, gadget, utf8_fn); + + /* corestring_dom___ns_key_file_name_node_data */ + LOG(("XYZZY: Setting userdata to %s", fn)); + if (dom_node_set_user_data((dom_node *)file_box->gadget->node, + corestring_dom___ns_key_file_name_node_data, + strdup(fn), html__dom_user_data_handler, + &oldfile) == DOM_NO_ERR) { + LOG(("XYZZY: Userdata used to be %s", oldfile)); + if (oldfile != NULL) + free(oldfile); + } + + /* Redraw box. */ + html__redraw_a_box(html, file_box); +} + +void html_set_file_gadget_filename(struct hlcache_handle *hl, + struct form_control *gadget, const char *fn) +{ + return html__set_file_gadget_filename(hlcache_handle_get_content(hl), + gadget, fn); +} + /** * Drop a file onto a content at a particular point, or determine if a file * may be dropped onto the content at given point. @@ -1794,35 +1834,7 @@ static bool html_drop_file_at_point(struct content *c, int x, int y, char *file) /* Handle the drop */ if (file_box) { /* File dropped on file input */ - utf8_convert_ret ret; - char *utf8_fn, *oldfile = NULL; - - ret = utf8_from_local_encoding(file, 0, - &utf8_fn); - if (ret != UTF8_CONVERT_OK) { - /* A bad encoding should never happen */ - assert(ret != UTF8_CONVERT_BADENC); - LOG(("utf8_from_local_encoding failed")); - /* Load was for us - just no memory */ - return true; - } - - /* Found: update form input */ - form_gadget_update_value(html, file_box->gadget, utf8_fn); - - /* corestring_dom___ns_key_file_name_node_data */ - LOG(("XYZZY: Setting userdata to %s", file)); - if (dom_node_set_user_data((dom_node *)file_box->gadget->node, - corestring_dom___ns_key_file_name_node_data, - strdup(file), html__dom_user_data_handler, - &oldfile) == DOM_NO_ERR) { - LOG(("XYZZY: Userdata used to be %s", oldfile)); - if (oldfile != NULL) - free(oldfile); - } - - /* Redraw box. */ - html__redraw_a_box(html, file_box); + html__set_file_gadget_filename(c, box->gadget, file); } else { /* File dropped on text input */ diff --git a/render/html.h b/render/html.h index 162541d72..7ca75e713 100644 --- a/render/html.h +++ b/render/html.h @@ -178,6 +178,8 @@ struct content_html_frames *html_get_frameset(struct hlcache_handle *h); struct content_html_iframe *html_get_iframe(struct hlcache_handle *h); nsurl *html_get_base_url(struct hlcache_handle *h); const char *html_get_base_target(struct hlcache_handle *h); +void html_set_file_gadget_filename(struct hlcache_handle *hl, + struct form_control *gadget, const char *fn); /** * Retrieve stylesheets used by HTML document diff --git a/render/html_object.c b/render/html_object.c index 7b34c4a7e..15ca7ed3b 100644 --- a/render/html_object.c +++ b/render/html_object.c @@ -368,6 +368,7 @@ html_object_callback(hlcache_handle *object, case CONTENT_MSG_SAVELINK: case CONTENT_MSG_POINTER: + case CONTENT_MSG_GADGETCLICK: /* These messages are for browser window layer. * we're not interested, so pass them on. */ content_broadcast(&c->base, event->type, event->data); -- cgit v1.2.3 From 550c8cd73c06f0984ce22b844d5a216d332cee43 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Sun, 5 Jan 2014 16:45:32 +0000 Subject: Change gui_file_gadget_interface to pass gui_window not browser_window, add GTK implementation that of course does not work. --- amiga/gui.c | 2 +- atari/gui.c | 2 +- beos/gui.cpp | 2 +- cocoa/gui.m | 2 +- desktop/browser.c | 2 +- desktop/gui.h | 2 +- gtk/gui.c | 7 ------- gtk/window.c | 32 ++++++++++++++++++++++++++++++++ monkey/browser.c | 2 +- riscos/gui.c | 2 +- 10 files changed, 40 insertions(+), 15 deletions(-) (limited to 'desktop') diff --git a/amiga/gui.c b/amiga/gui.c index 76185e949..8027eeba0 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -5138,7 +5138,7 @@ void ami_gui_splash_close(Object *win_obj) if(win_obj) DisposeObject(win_obj); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/atari/gui.c b/atari/gui.c index badb4206c..3b3e98943 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1098,7 +1098,7 @@ static void gui_init2(int argc, char** argv) toolbar_init(); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/beos/gui.cpp b/beos/gui.cpp index 6c9d1ed12..42edc61aa 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -1165,7 +1165,7 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/cocoa/gui.m b/cocoa/gui.m index 3804ad249..7ee2372f3 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -324,7 +324,7 @@ void gui_401login_open(nsurl *url, const char *realm, cb( false, cbpw ); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/desktop/browser.c b/desktop/browser.c index 3d279f727..6ec31d22f 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -1564,7 +1564,7 @@ static nserror browser_window_callback(hlcache_handle *c, case CONTENT_MSG_GADGETCLICK: if (event->data.gadget_click.gadget->type == GADGET_FILE) { - gui_file_gadget_open(bw, c, + gui_file_gadget_open(bw->window, c, event->data.gadget_click.gadget); } diff --git a/desktop/gui.h b/desktop/gui.h index 4bbf08718..26a9f4b43 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -116,7 +116,7 @@ void gui_drag_save_selection(struct gui_window *g, const char *selection); void gui_start_selection(struct gui_window *g); void gui_clear_selection(struct gui_window *g); -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget); /** diff --git a/gtk/gui.c b/gtk/gui.c index 0f815a7a2..77b72f874 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -681,13 +681,6 @@ void gui_quit(void) gtk_fetch_filetype_fin(); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, - struct form_control *gadget) -{ - LOG(("File open dialog rquest for %p/%p", bw, gadget)); - /* browser_window_set_gadget_filename(bw, gadget, "plinth"); */ -} - static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem, gpointer user_data) { diff --git a/gtk/window.c b/gtk/window.c index 8f449ced2..8f05c3799 100644 --- a/gtk/window.c +++ b/gtk/window.c @@ -1162,3 +1162,35 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, LOG(("width: %i", *width)); LOG(("height: %i", *height)); } + +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, + struct form_control *gadget) +{ + GtkWidget *dialog; + + LOG(("Awooga.")); + + dialog = gtk_file_chooser_dialog_new("Select File", + nsgtk_scaffolding_window(g->scaffold), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + LOG(("*** open dialog: %p", dialog)); + + int ret = gtk_dialog_run(GTK_DIALOG(dialog)); + LOG(("*** return value: %d", ret)); + if (ret == GTK_RESPONSE_ACCEPT) { + char *filename; + + filename = gtk_file_chooser_get_filename( + GTK_FILE_CHOOSER(dialog)); + + browser_window_set_gadget_filename(g->bw, gadget, filename); + + g_free(filename); + } + + gtk_widget_destroy(dialog); +} diff --git a/monkey/browser.c b/monkey/browser.c index 47fb07bc1..7c28cf8a3 100644 --- a/monkey/browser.c +++ b/monkey/browser.c @@ -390,7 +390,7 @@ gui_window_save_link(struct gui_window *g, const char *url, g->win_num, url, title); } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_browser *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); diff --git a/riscos/gui.c b/riscos/gui.c index 0c8ebecc7..900915483 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2424,7 +2424,7 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -void gui_file_gadget_open(struct browser_window *bw, hlcache_handle *hl, +void gui_file_gadget_open(struct gui_window *g, hlcache_handle *hl, struct form_control *gadget) { LOG(("File open dialog rquest for %p/%p", bw, gadget)); -- cgit v1.2.3