Exemplo n.º 1
0
bool ro_gui_options_connection_ok(wimp_w w)
{
	int proxy_type;

	proxy_type = ro_gui_options_connection_proxy_type(w);
	if (proxy_type == 0)
		option_http_proxy = false;
	else {
		option_http_proxy = true;
		option_http_proxy_auth = proxy_type - 1;
	}
	if (option_http_proxy_host)
		free(option_http_proxy_host);
	option_http_proxy_host = strdup(ro_gui_get_icon_string(w,
			CONNECTION_PROXY_HOST));
	option_http_proxy_port = ro_gui_get_icon_decimal(w,
			CONNECTION_PROXY_PORT, 0);
	if (option_http_proxy_auth_user)
		free(option_http_proxy_auth_user);
	option_http_proxy_auth_user = strdup(ro_gui_get_icon_string(w,
			CONNECTION_PROXY_USERNAME));
	if (option_http_proxy_auth_pass)
		free(option_http_proxy_auth_pass);
	option_http_proxy_auth_pass = strdup(ro_gui_get_icon_string(w,
			CONNECTION_PROXY_PASSWORD));
	option_max_fetchers = ro_gui_get_icon_decimal(w,
			CONNECTION_MAX_FETCH_FIELD, 0);
	option_max_fetchers_per_host = ro_gui_get_icon_decimal(w,
			CONNECTION_HOST_FETCH_FIELD, 0);
	option_max_cached_fetch_handles = ro_gui_get_icon_decimal(w,
			CONNECTION_CACHE_FETCH_FIELD, 0);

	ro_gui_save_options();
	return true;
}
Exemplo n.º 2
0
void ro_gui_save_drag_end(wimp_dragged *drag)
{
	char *name;
	char *dot;
	wimp_pointer pointer;
	wimp_message message;

	wimp_get_pointer_info(&pointer);

	name = ro_gui_get_icon_string(dialog_saveas, ICON_SAVE_PATH);
	dot = strrchr(name, '.');
	if (dot)
		name = dot + 1;

	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 = gui_save_filetype;
	strncpy(message.data.data_xfer.file_name, name, 212);
	message.data.data_xfer.file_name[211] = 0;
	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);
}
Exemplo n.º 3
0
bool ro_gui_download_keypress(wimp_key *key)
{
  	struct gui_download_window *dw;

	dw = (struct gui_download_window *)ro_gui_wimp_event_get_user_data(key->w);
	switch (key->c)
	{
		case wimp_KEY_ESCAPE:
			ro_gui_download_window_destroy(dw, false);
			return true;

		case wimp_KEY_RETURN: {
			const char *name = ro_gui_get_icon_string(dw->window,
					ICON_DOWNLOAD_PATH);
			if (!strrchr(name, '.')) {
				warn_user("NoPathError", NULL);
				return true;
			}
			ro_gui_convert_save_path(dw->path, sizeof dw->path, name);

			dw->send_dataload = false;
			if (ro_gui_download_save(dw, dw->path,
					!option_confirm_overwrite) && !dw->ctx)
			{
				/* finished already */
				schedule(200, ro_gui_download_window_destroy_wrapper, dw);
			}
			return true;
		}
		break;
	}

	/* ignore all other keypresses (F12 etc) */
	return false;
}
Exemplo n.º 4
0
/**
 * Handle OK click/keypress in the save dialog.
 *
 * \param  w  window handle of save dialog
 * \return true on success, false on failure
 */
bool ro_gui_save_ok(wimp_w w)
{
	const char *name = ro_gui_get_icon_string(w, ICON_SAVE_PATH);
	wimp_pointer pointer;
	char path[256];

	if (!strrchr(name, '.')) {
		warn_user("NoPathError", NULL);
		return false;
	}

	ro_gui_convert_save_path(path, sizeof path, name);
	gui_save_sourcew = w;
	saving_from_dialog = true;
	gui_save_send_dataload = false;
	gui_save_close_after = xwimp_get_pointer_info(&pointer)
						|| !(pointer.buttons & wimp_CLICK_ADJUST);
	memcpy(&gui_save_message.data.data_xfer.file_name, path, 1 + strlen(path));

	if (ro_gui_save_content(gui_save_content, path, !option_confirm_overwrite)) {
		ro_gui_save_done();
		return true;
	}
	return false;
}
Exemplo n.º 5
0
bool ro_gui_options_interface_ok(wimp_w w)
{
	nsoption_set_bool(strip_extensions, 
			ro_gui_get_icon_selected_state(w, 
					INTERFACE_STRIP_EXTNS_OPTION));
	nsoption_set_bool(confirm_overwrite, 
                          ro_gui_get_icon_selected_state(w,
                                        INTERFACE_CONFIRM_OVWR_OPTION));
	nsoption_set_bool(url_suggestion, 
                          ro_gui_get_icon_selected_state(w,
                                        INTERFACE_URL_COMPLETE_OPTION));
	nsoption_set_bool(history_tooltip, 
                          ro_gui_get_icon_selected_state(w,
                                        INTERFACE_HISTORY_TOOLTIP_OPTION));
	nsoption_set_bool(thumbnail_iconise, 
                          ro_gui_get_icon_selected_state(w,
                                        INTERFACE_THUMBNAIL_ICONISE_OPTION));
	nsoption_set_bool(external_hotlists, 
                          ro_gui_get_icon_selected_state(w,
                                        INTERFACE_USE_EXTERNAL_HOTLIST));
	nsoption_set_charp(external_hotlist_app,
                           strdup(ro_gui_get_icon_string(w,
                                        INTERFACE_EXTERNAL_HOTLIST_APP)));

	ro_gui_save_options();
	return true;
}
Exemplo n.º 6
0
void ro_gui_save_click(wimp_pointer *pointer)
{
	switch (pointer->i) {
	  	case ICON_SAVE_OK:
	  		close_menu = (pointer->buttons == wimp_CLICK_SELECT);
	  		ro_gui_save(ro_gui_get_icon_string(dialog_saveas, ICON_SAVE_PATH));
	  		if (pointer->buttons == wimp_CLICK_SELECT) {
	  		  	xwimp_create_menu((wimp_menu *)-1, 0, 0);
	  		  	ro_gui_dialog_close(pointer->w);
	  		}
	  		break;
	  	case ICON_SAVE_CANCEL:
	  		if (pointer->buttons == wimp_CLICK_SELECT) {
	  		  	xwimp_create_menu((wimp_menu *)-1, 0, 0);
	  		  	ro_gui_dialog_close(pointer->w);
	  		} else if (pointer->buttons == wimp_CLICK_ADJUST) {
	  			ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, reset_filename);
	  		}
	  		break;
		case ICON_SAVE_ICON:
			if (pointer->buttons == wimp_DRAG_SELECT) {
				ro_gui_drag_icon(pointer);
			}
			break;
	}
}
Exemplo n.º 7
0
void ro_gui_options_image_read(wimp_w w, unsigned int *bg, unsigned int *fg)
{
	const char *text;
	int i;

	text = ro_gui_get_icon_string(w, IMAGE_FOREGROUND_FIELD);
	for (i = 0; i < 4; i++)
		if (!strcmp(text, image_quality_menu->entries[i].
				data.indirected_text.text))
			*fg = tinct_options[i];

	text = ro_gui_get_icon_string(w, IMAGE_BACKGROUND_FIELD);
	for (i = 0; i < 4; i++)
		if (!strcmp(text, image_quality_menu->entries[i].
				data.indirected_text.text))
			*bg = tinct_options[i];
}
Exemplo n.º 8
0
bool ro_gui_options_home_ok(wimp_w w)
{
	nsoption_set_charp(homepage_url,
		       strdup(ro_gui_get_icon_string(w, HOME_URL_FIELD)));

	nsoption_set_bool(open_browser_at_startup,
			  ro_gui_get_icon_selected_state(w, HOME_OPEN_STARTUP));

	ro_gui_save_options();
  	return true;
}
Exemplo n.º 9
0
int ro_gui_options_connection_proxy_type(wimp_w w)
{
	const char *text;
	int i;

	text = ro_gui_get_icon_string(w, CONNECTION_PROXY_FIELD);
	for (i = 0; (i < 4); i++)
		if (!strcmp(text, proxy_type_menu->entries[i].
				data.indirected_text.text))
			return i;
	assert(false);
}
Exemplo n.º 10
0
bool ro_gui_options_language_ok(wimp_w w)
{
	const char *code;
	char *temp;

	code = ro_gui_menu_find_menu_entry_key(languages_menu,
			ro_gui_get_icon_string(w, LANGUAGE_INTERFACE_FIELD));
	if (code) {
		code += 5;	/* skip 'lang_' */
		if ((!nsoption_charp(language)) || 
                    (strcmp(nsoption_charp(language), code))) {
			temp = strdup(code);
			if (temp) {
				nsoption_set_charp(language, temp);
			} else {
				LOG("No memory to duplicate language code");
				warn_user("NoMemory", 0);
			}
		}
	}
	code = ro_gui_menu_find_menu_entry_key(languages_menu,
			ro_gui_get_icon_string(w, LANGUAGE_WEB_PAGES_FIELD));
	if (code) {
		code += 5;	/* skip 'lang_' */
		if ((!nsoption_charp(accept_language)) ||
                    (strcmp(nsoption_charp(accept_language), code))) {
			temp = strdup(code);
			if (temp) {
				nsoption_set_charp(accept_language,temp);
			} else {
				LOG("No memory to duplicate language code");
				warn_user("NoMemory", 0);
			}
		}
	}
	ro_gui_save_options();
	return true;
}
Exemplo n.º 11
0
/**
 * Should be called when the caret is placed into a URL completion icon.
 *
 * \param g    the gui_window to initialise URL completion for
 */
void ro_gui_url_complete_start(struct gui_window *g)
{
	const char *url;

	if ((!g->toolbar) || (!g->toolbar->display_url) ||
			(g->window == url_complete_parent))
		return;

	ro_gui_url_complete_close(NULL, 0);
	url = ro_gui_get_icon_string(g->toolbar->toolbar_handle,
			ICON_TOOLBAR_URL);

	url_complete_matched_string = strdup(url);
	if (url_complete_matched_string)
		url_complete_parent = g->window;
}
Exemplo n.º 12
0
bool ro_gui_download_click(wimp_pointer *pointer)
{
  	struct gui_download_window *dw;

	dw = (struct gui_download_window *)ro_gui_wimp_event_get_user_data(pointer->w);
	if ((pointer->buttons & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST)) &&
			pointer->i == ICON_DOWNLOAD_ICON && 
			!dw->error && !dw->saved) {
		const char *sprite = ro_gui_get_icon_string(pointer->w, pointer->i);
		int x = pointer->pos.x, y = pointer->pos.y;
		wimp_window_state wstate;
		wimp_icon_state istate;
		/* start the drag from the icon's exact location, rather than the pointer */
		istate.w = wstate.w = pointer->w;
		istate.i = pointer->i;
		if (!xwimp_get_window_state(&wstate) && !xwimp_get_icon_state(&istate)) {
			x = (istate.icon.extent.x1 + istate.icon.extent.x0)/2 +
					wstate.visible.x0 - wstate.xscroll;
			y = (istate.icon.extent.y1 + istate.icon.extent.y0)/2 +
					wstate.visible.y1 - wstate.yscroll;
		}
		ro_mouse_drag_start(ro_gui_download_drag_end, NULL, NULL, NULL);
		download_window_current = dw;
		ro_gui_drag_icon(x, y, sprite);

	} else if (pointer->i == ICON_DOWNLOAD_DESTINATION) {
		char command[256] = "Filer_OpenDir ";
		char *dot;

		strncpy(command + 14, dw->path, 242);
		command[255] = 0;
		dot = strrchr(command, '.');
		if (dot) {
			os_error *error;
			*dot = 0;
			error = xos_cli(command);
			if (error) {
				LOG("xos_cli: 0x%x: %s", error->errnum, error->errmess);
				ro_warn_user("MiscError", error->errmess);
			}
		}
	}
	return true;
}
Exemplo n.º 13
0
void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url,
		bool is_utf8, bool set_caret)
{
	wimp_caret	caret;
	os_error	*error;
	const char	*set_url;

	if (url_bar == NULL || url_bar->text_buffer == NULL)
		return;

	if (url_bar->text_icon == -1) {
		strncpy(url_bar->text_buffer, url, url_bar->text_size);
		return;
	}

	ro_gui_set_icon_string(url_bar->window, url_bar->text_icon,
			url, is_utf8);

	error = xwimp_get_caret_position(&caret);
	if (error) {
		LOG(("xwimp_get_caret_position: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}

	if (set_caret || (caret.w == url_bar->window &&
			caret.i == url_bar->text_icon)) {
		set_url = ro_gui_get_icon_string(url_bar->window,
				url_bar->text_icon);

		error = xwimp_set_caret_position(url_bar->window,
				url_bar->text_icon, 0, 0, -1, strlen(set_url));
		if (error) {
			LOG(("xwimp_set_caret_position: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("WimpError", error->errmess);
		}
	}
}
Exemplo n.º 14
0
/**
 * Starts a drag for the save dialog
 *
 * \param  pointer  mouse position info from Wimp
 */
void ro_gui_save_start_drag(wimp_pointer *pointer)
{
	if (pointer->buttons & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST)) {
		const char *sprite = ro_gui_get_icon_string(pointer->w, pointer->i);
		int x = pointer->pos.x, y = pointer->pos.y;
		wimp_window_state wstate;
		wimp_icon_state istate;
		/* start the drag from the icon's exact location, rather than the pointer */
		istate.w = wstate.w = pointer->w;
		istate.i = pointer->i;
		if (!xwimp_get_window_state(&wstate) && !xwimp_get_icon_state(&istate)) {
			x = (istate.icon.extent.x1 + istate.icon.extent.x0)/2 +
					wstate.visible.x0 - wstate.xscroll;
			y = (istate.icon.extent.y1 + istate.icon.extent.y0)/2 +
					wstate.visible.y1 - wstate.yscroll;
		}
		gui_current_drag_type = GUI_DRAG_SAVE;
		gui_save_sourcew = pointer->w;
		saving_from_dialog = true;
		gui_save_close_after = !(pointer->buttons & wimp_DRAG_ADJUST);
		ro_gui_drag_icon(x, y, sprite);
	}
}
Exemplo n.º 15
0
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) {
		LOG(("xdragasprite_start: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("DragError", error->errmess);
	}
}
Exemplo n.º 16
0
bool ro_gui_options_fonts_ok(wimp_w w)
{
	unsigned int i;

	nsoption_set_int(font_size,
			 ro_gui_get_icon_decimal(w, FONT_DEFAULT_SIZE, 1));

	nsoption_set_int(font_min_size,
			 ro_gui_get_icon_decimal(w, FONT_MINIMUM_SIZE, 1));

	if (nsoption_int(font_size) < nsoption_int(font_min_size)) {
		nsoption_set_int(font_size, nsoption_int(font_min_size));
		ro_gui_set_icon_decimal(w, FONT_DEFAULT_SIZE, nsoption_int(font_size), 1);
	
}

	nsoption_set_charp(font_sans,
			   strdup(ro_gui_get_icon_string(w, FONT_SANS_FIELD)));

	nsoption_set_charp(font_serif,
			   strdup(ro_gui_get_icon_string(w, FONT_SERIF_FIELD)));

	nsoption_set_charp(font_mono,
			   strdup(ro_gui_get_icon_string(w, FONT_MONOSPACE_FIELD)));

	nsoption_set_charp(font_cursive,
			   strdup(ro_gui_get_icon_string(w, FONT_CURSIVE_FIELD)));

	nsoption_set_charp(font_fantasy,
			   strdup(ro_gui_get_icon_string(w, FONT_FANTASY_FIELD)));

	for (i = 0; i != 5; i++) {
		if (!strcmp(font_names[i], ro_gui_get_icon_string(w,
				FONT_DEFAULT_FIELD)))
			break;
	}
	if (i == 5)
		/* this should never happen, but still */
		i = 0;

	nsoption_set_int(font_default, i);

	ro_gui_save_options();
	return true;
}
Exemplo n.º 17
0
/**
 * Handle mouse clicks in the URL completion window.
 *
 * \param pointer  the pointer state
 * \return whether the click was handled
 */
bool ro_gui_url_complete_click(wimp_pointer *pointer)
{
	wimp_window_state state;
	os_error *error;
	int selection, old_selection;
	struct gui_window *g;
	const char *url;

	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));
		warn_user("WimpError", error->errmess);
		return false;
	}

	selection = (state.visible.y1 - pointer->pos.y - state.yscroll) / 44;
	if (selection != url_complete_matches_selection) {
		if (url_complete_matches_selection == -1) {
			g = ro_gui_window_lookup(url_complete_parent);
			if (!g)
				return false;
			url = ro_gui_get_icon_string(
					g->toolbar->toolbar_handle,
					ICON_TOOLBAR_URL);
			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));
			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));
			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_gui_set_icon_string(g->toolbar->toolbar_handle,
				ICON_TOOLBAR_URL,
				url_complete_matches[
					url_complete_matches_selection], true);
		global_history_add_recent(url_complete_matches[
					url_complete_matches_selection]);

		/** \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_go.
		 * They will be invalidated by (at least):
		 *   + 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_go(g->bw,
				url_complete_matches[
					url_complete_matches_selection],
				0, true);
		ro_gui_url_complete_close(NULL, 0);

	/* Adjust just sets the text */
	} else if (pointer->buttons == wimp_CLICK_ADJUST) {
		ro_gui_set_icon_string(g->toolbar->toolbar_handle,
				ICON_TOOLBAR_URL,
				url_complete_matches[
					url_complete_matches_selection], true);
		ro_gui_url_complete_keypress(g, 0);
	}
	return true;
}
Exemplo n.º 18
0
bool ro_gui_save_theme(char *path) {
  	os_error *error;
	struct theme_file_header *file_header;
	char *workspace;
	int workspace_size, output_size, input_left, output_left;
	squash_output_status status;

	/*	Get some memory
	*/
	unsigned int file_size = sizeof (struct theme_file_header);
	file_header = (struct theme_file_header *)calloc(file_size, 1);
	if (!file_header) {
	  	LOG(("No memory for calloc()"));
		warn_user("NoMemory", 0);
		return false;
	}

	/*	Complete the header
	*/
	file_header->magic_value = 0x4d54534e;
	file_header->parser_version = 2;
	strcpy(file_header->name, ro_gui_get_icon_string(dialog_main, ICON_MAIN_NAME));
	strcpy(file_header->author, ro_gui_get_icon_string(dialog_main, ICON_MAIN_AUTHOR));
	file_header->browser_bg = ro_gui_get_icon_background_colour(dialog_main,
			ICON_MAIN_BROWSER_COLOUR);
	file_header->hotlist_bg = ro_gui_get_icon_background_colour(dialog_main,
			ICON_MAIN_HOTLIST_COLOUR);
	file_header->status_bg = ro_gui_get_icon_background_colour(dialog_main,
			ICON_MAIN_STATUSBG_COLOUR);
	file_header->status_fg = ro_gui_get_icon_background_colour(dialog_main,
			ICON_MAIN_STATUSFG_COLOUR);
	if (ro_gui_get_icon_selected_state(dialog_main, ICON_MAIN_THROBBER_LEFT))
		file_header->theme_flags = (1 << 0);
	if (ro_gui_get_icon_selected_state(dialog_main, ICON_MAIN_THROBBER_REDRAW))
		file_header->theme_flags = (1 << 1);


	/*	Append the compressed sprites
	*/
	if (theme_sprites) {
		file_header->decompressed_sprite_size = theme_sprites->size;
		error = xsquash_compress_return_sizes(theme_sprites->size,
				&workspace_size, &output_size);
		if (error) {
		  	free(file_header);
			LOG(("xsquash_compress_return_sizes: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("MiscError", error->errmess);
			return false;
		}
		workspace = realloc(file_header,
				file_size + output_size);
		if (!workspace) {
		  	free(file_header);
			LOG(("No memory for realloc()"));
			warn_user("NoMemory", 0);
			return false;
		}
		file_header = (struct theme_file_header *)workspace;
		workspace = malloc(workspace_size);
		if (!workspace) {
		  	free(file_header);
			LOG(("No memory for malloc()"));
			warn_user("NoMemory", 0);
			return false;
		}
		error = xsquash_compress((squash_input_status)0,
				workspace, (byte *)theme_sprites,
				theme_sprites->size,
				(byte *)(file_header + 1), output_size,
				&status, 
				0, &input_left, 0, &output_left);
	  	free(workspace);
		if (error) {
		  	free(file_header);
			LOG(("xsquash_compress: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("MiscError", error->errmess);
			return false;
		}
		if ((input_left > 0) || (status != 0)) {
		  	free(file_header);
		  	LOG(("Failed to complete compression with %i bytes left and status %i",
		  		input_left, (int)status));
		  	warn_user("FileError", 0);
		  	return false;
		}
		file_header->compressed_sprite_size = output_size - output_left;
		file_size += output_size - output_left;
	}
	
	/*	Save the file
	*/
	error = xosfile_save_stamped(path, (bits)0xffd,
			(char *)file_header, ((char *)file_header) + file_size);
	free(file_header);
	if (error) {
		LOG(("xosfile_save_stamped: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("FileError", error->errmess);
		return false;
	}
	return false;
}
Exemplo n.º 19
0
/**
 * Handles a keypress for URL completion
 *
 * \param g    the gui_window to update
 * \param key  the key pressed (as UTF32 code or wimp key + bit31 set)
 * \return true to indicate keypress handled, false otherwise
 */
bool ro_gui_url_complete_keypress(struct gui_window *g, uint32_t key)
{
	wimp_window_state state;
	char *match_url;
	const char *url;
	int i, lines;
	int old_selection;
	int height;
	os_error *error;
	bool currently_open;

	/* we must have a toolbar/url bar */
	if ((!g->toolbar) || (!g->toolbar->display_url) ||
			(!option_url_suggestion)) {
		ro_gui_url_complete_close(NULL, 0);
		return false;
	}

	/* if we are currently active elsewhere, remove the previous window */
	currently_open = ((g->window == url_complete_parent) &&
			(url_complete_matches_available > 0));
	if (g->window != url_complete_parent)
		ro_gui_url_complete_close(NULL, 0);

	/* forcibly open on down keys */
	if ((!currently_open) && (url_complete_matched_string)) {
		switch (key) {
			case IS_WIMP_KEY | wimp_KEY_DOWN:
			case IS_WIMP_KEY | wimp_KEY_PAGE_DOWN:
			case IS_WIMP_KEY | wimp_KEY_CONTROL | wimp_KEY_DOWN:
				free(url_complete_matched_string);
				url_complete_matched_string = NULL;
		}
	}


	/* get the text to match */
	url_complete_parent = g->window;
	url = ro_gui_get_icon_string(g->toolbar->toolbar_handle,
			ICON_TOOLBAR_URL);
	match_url = strdup(url);
	if (!match_url) {
		ro_gui_url_complete_close(NULL, 0);
		return false;
	}

	/* if the text to match has changed then update it */
	if ((!url_complete_matched_string) ||
			(strcmp(match_url, url_complete_matched_string))) {

		/* memorize the current matches */
		lines = MAXIMUM_VISIBLE_LINES;
		if (lines > url_complete_matches_available)
			lines = url_complete_matches_available;
		if (url_complete_matches) {
			for (i = 0; i < MAXIMUM_VISIBLE_LINES; i++) {
				if (i < lines) {
					url_complete_redraw[i] = 
						url_complete_matches[i];
				} else {
					url_complete_redraw[i] = NULL;
				}
			}
		}

		/* our selection gets wiped */
		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));
			warn_user("WimpError", error->errmess);
		}

		/* clear our state */
		free(url_complete_original_url);
		free(url_complete_matched_string);
		url_complete_matched_string = match_url;
		url_complete_original_url = NULL;
		url_complete_matches_available = 0;
		url_complete_matches_selection = -1;
		url_complete_keypress_selection = -1;

		/* get some initial memory */
		if (!url_complete_matches) {
			url_complete_matches = malloc(64 * sizeof(char *));
			if (!url_complete_matches) {
				ro_gui_url_complete_close(NULL, 0);
				return false;
			}
			url_complete_matches_allocated = 64;
		}

		/* find matches */
		url_complete_memory_exhausted = false;
		if (strlen(match_url) == 0)
			urldb_iterate_entries(url_complete_callback);
		else
			urldb_iterate_partial(match_url, url_complete_callback);
		if ((url_complete_memory_exhausted) ||
				(url_complete_matches_available == 0)) {
			ro_gui_url_complete_close(NULL, 0);
			return false;
		}

		/* update the window */
		state.w = g->window;
		error = xwimp_get_window_state(&state);
		if (error) {
			LOG(("xwimp_get_window_state: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("WimpError", error->errmess);
			return false;
		}
		url_complete_matches_reset = true;
		ro_gui_url_complete_resize(g, PTR_WIMP_OPEN(&state));
		url_complete_matches_reset = false;

		/* redraw the relevant bits of the window */
		lines = MAXIMUM_VISIBLE_LINES;
		if (lines > url_complete_matches_available)
			lines = url_complete_matches_available;
		for (i = 0; i < lines; i++) {
			if (url_complete_redraw[i] !=
					url_complete_matches[i]) {
				error = xwimp_force_redraw(dialog_url_complete,
					0, -(i + 1) * 44, 65536, -i * 44);
				if (error) {
					LOG(("xwimp_force_redraw: 0x%x: %s",
							error->errnum,
							error->errmess));
					warn_user("WimpError",
							error->errmess);
				}
			}
		}
	} else {
		free(match_url);
	}

	/* handle keypresses */
	if (!currently_open)
		return false;

	old_selection = url_complete_matches_selection;

	switch (key) {
		case IS_WIMP_KEY | wimp_KEY_UP:
			url_complete_matches_selection--;
			break;
		case IS_WIMP_KEY | wimp_KEY_DOWN:
			url_complete_matches_selection++;
			break;
		case IS_WIMP_KEY | wimp_KEY_PAGE_UP:
			url_complete_matches_selection -=
					MAXIMUM_VISIBLE_LINES;
			break;
		case IS_WIMP_KEY | wimp_KEY_PAGE_DOWN:
			url_complete_matches_selection +=
					MAXIMUM_VISIBLE_LINES;
			break;
		case IS_WIMP_KEY | wimp_KEY_CONTROL | wimp_KEY_UP:
			url_complete_matches_selection = 0;
			break;
		case IS_WIMP_KEY | wimp_KEY_CONTROL | wimp_KEY_DOWN:
			url_complete_matches_selection = 65536;
			break;
	}

	if (url_complete_matches_selection >
			url_complete_matches_available - 1)
		url_complete_matches_selection =
				url_complete_matches_available - 1;
	else if (url_complete_matches_selection < -1)
		url_complete_matches_selection = -1;

	if (old_selection == url_complete_matches_selection)
		return false;

	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));
		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));
		warn_user("WimpError", error->errmess);
	}

	if (old_selection == -1) {
		free(url_complete_original_url);
		url_complete_original_url = malloc(strlen(url) + 1);
		if (!url_complete_original_url)
			return false;
		strcpy(url_complete_original_url, url);
	}

	if (url_complete_matches_selection == -1) {
		ro_gui_set_icon_string(g->toolbar->toolbar_handle,
				ICON_TOOLBAR_URL,
				url_complete_original_url, true);
	} else {
		ro_gui_set_icon_string(g->toolbar->toolbar_handle,
				ICON_TOOLBAR_URL,
				url_complete_matches[
					url_complete_matches_selection], true);
		free(url_complete_matched_string);
		url_complete_matched_string = strdup(url_complete_matches[
					url_complete_matches_selection]);
	}
	url_complete_keypress_selection = url_complete_matches_selection;

	/* auto-scroll */
	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));
		warn_user("WimpError", error->errmess);
		return true;
	}

	if (state.yscroll < -(url_complete_matches_selection * 44))
		state.yscroll = -(url_complete_matches_selection * 44);
	height = state.visible.y1 - state.visible.y0;
	if (state.yscroll - height >
			-((url_complete_matches_selection + 1) * 44))
		state.yscroll =
			-((url_complete_matches_selection + 1) * 44) + height;

	error = xwimp_open_window(PTR_WIMP_OPEN(&state));
	if (error) {
		LOG(("xwimp_open_window: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return true;
	}

	return true;
}