예제 #1
0
파일: save.c 프로젝트: pombredanne/NetSurf
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)) {
			dest_ok = browser_window_drop_file_at_point(g->bw,
					pos.x, pos.y, NULL);
		}
		if (!dest_ok) {
			/* cancel the drag operation */
			gui_current_drag_type = GUI_DRAG_NONE;
			return;
		}
	}
예제 #2
0
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;
		}
	}
예제 #3
0
bool ro_gui_url_complete_click(wimp_pointer *pointer)
{
	wimp_window_state state;
	os_error *error;
	int selection;
	struct gui_window *g;

	if ((mouse_x == pointer->pos.x) && (mouse_y == pointer->pos.y) &&
			(!pointer->buttons))
		return false;

	mouse_x = pointer->pos.x;
	mouse_y = pointer->pos.y;

	state.w = dialog_url_complete;
	error = xwimp_get_window_state(&state);
	if (error) {
		LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
		ro_warn_user("WimpError", error->errmess);
		return false;
	}

	selection = (state.visible.y1 - pointer->pos.y - state.yscroll) / 44;
	if (selection != url_complete_matches_selection) {
		int old_selection;

		if (url_complete_matches_selection == -1) {
			const char *url;

			g = ro_gui_window_lookup(url_complete_parent);
			if (!g)
				return false;
			url = ro_toolbar_get_url(g->toolbar);
			free(url_complete_original_url);
			url_complete_original_url = strdup(url);
			if (!url_complete_original_url)
				return false;
		}
		old_selection = url_complete_matches_selection;
		url_complete_matches_selection = selection;
		error = xwimp_force_redraw(dialog_url_complete,
				0, -(old_selection + 1) * 44,
				65536, -old_selection * 44);
		if (error) {
			LOG("xwimp_force_redraw: 0x%x: %s", error->errnum, error->errmess);
			ro_warn_user("WimpError", error->errmess);
		}
		error = xwimp_force_redraw(dialog_url_complete,
				0, -(url_complete_matches_selection + 1) * 44,
				65536, -url_complete_matches_selection * 44);
		if (error) {
			LOG("xwimp_force_redraw: 0x%x: %s", error->errnum, error->errmess);
			ro_warn_user("WimpError", error->errmess);
		}
	}
	if (!pointer->buttons)
		return true;

	/* find owning window */
	g = ro_gui_window_lookup(url_complete_parent);
	if (!g)
		return false;

	/* Select sets the text and launches */
	if (pointer->buttons == wimp_CLICK_SELECT) {
		ro_toolbar_set_url(g->toolbar,
				nsurl_access(url_complete_matches[
					url_complete_matches_selection]),
				true, false);

		/** \todo The interaction of components here is hideous */
		/* Do NOT make any attempt to use any of the global url
		 * completion variables after this call to browser_window_navigate.
		 * They will be invalidated by (at least):
		 *   + ro_gui_window_set_url
		 *   + destruction of (i)frames within the current page
		 * Any attempt to use them will probably result in a crash.
		 */

		browser_window_navigate(g->bw,
			url_complete_matches[url_complete_matches_selection],
			NULL,
			BW_NAVIGATE_HISTORY,
			NULL,
			NULL,
			NULL);

		ro_gui_url_complete_close();

	/* Adjust just sets the text */
	} else if (pointer->buttons == wimp_CLICK_ADJUST) {
		ro_toolbar_set_url(g->toolbar,
				nsurl_access(url_complete_matches[
					url_complete_matches_selection]),
				true, false);
		ro_gui_url_complete_keypress(g->toolbar, 0);
	}
	return true;
}