void save_as_text(hlcache_handle *c, char *path) { FILE *out; struct save_text_state save = { NULL, 0, 0 }; save_text_whitespace before = WHITESPACE_NONE; bool first = true; nserror ret; char *result; if (!c || content_get_type(c) != CONTENT_HTML) { return; } extract_text(html_get_box_tree(c), &first, &before, &save); if (!save.block) return; ret = guit->utf8->utf8_to_local(save.block, save.length, &result); free(save.block); if (ret != NSERROR_OK) { LOG(("failed to convert to local encoding, return %d", ret)); return; } out = fopen(path, "w"); if (out) { int res = fputs(result, out); if (res < 0) { LOG(("Warning: write failed")); } res = fputs("\n", out); if (res < 0) { LOG(("Warning: failed writing trailing newline")); } fclose(out); } free(result); }
void ro_gui_save_drag_end(wimp_dragged *drag) { const char *name; wimp_pointer pointer; wimp_message message; os_error *error; char *dp, *ep; char *local_name = NULL; utf8_convert_ret err; if (dragbox_active) ro_gui_drag_box_cancel(); error = xwimp_get_pointer_info(&pointer); if (error) { LOG(("xwimp_get_pointer_info: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return; } /* perform hit-test if the destination is the same as the source window; we want to allow drag-saving from a page into the input fields within the page, but avoid accidental replacements of the current page */ if (gui_save_sourcew != (wimp_w)-1 && pointer.w == gui_save_sourcew) { int dx = (drag->final.x1 + drag->final.x0)/2; int dy = (drag->final.y1 + drag->final.y0)/2; struct gui_window *g; bool dest_ok = false; os_coord pos; g = ro_gui_window_lookup(gui_save_sourcew); if (g && ro_gui_window_to_window_pos(g, dx, dy, &pos)) { hlcache_handle *h = g->bw->current_content; if (h && content_get_type(h) == CONTENT_HTML) { struct box *box = html_get_box_tree(h); int box_x, box_y; /* Consider the margins of the html page now */ box_x = box->margin[LEFT]; box_y = box->margin[TOP]; while (!dest_ok && (box = box_at_point(box, pos.x, pos.y, &box_x, &box_y, &h))) { if (box->style && css_computed_visibility( box->style) == CSS_VISIBILITY_HIDDEN) continue; if (box->gadget) { switch (box->gadget->type) { case GADGET_FILE: case GADGET_TEXTBOX: case GADGET_TEXTAREA: case GADGET_PASSWORD: dest_ok = true; break; default: /* appease compiler */ break; } } } } } if (!dest_ok) { /* cancel the drag operation */ gui_current_drag_type = GUI_DRAG_NONE; return; } }