bool ro_gui_url_bar_set_extent(struct url_bar *url_bar, int x0, int y0, int x1, int y1) { bool stretch; if (url_bar == NULL) return false; if ((x1 - x0) < url_bar->x_min || (y1 - y0) < url_bar->y_min) return false; if (url_bar->extent.x0 == x0 && url_bar->extent.y0 == y0 && url_bar->extent.x1 == x1 && url_bar->extent.y1 == y1) return true; /* If it's only the length that changes, less needs to be updated. */ stretch = (url_bar->extent.x0 == x0 && url_bar->extent.y0 == y0 && url_bar->extent.y1 == y1) ? true : false; /* Redraw the relevant bits of the toolbar. */ if (url_bar->window != NULL && !url_bar->hidden) { if (stretch) { xwimp_force_redraw(url_bar->window, x0 + URLBAR_FAVICON_WIDTH, y0, (x1 > url_bar->extent.x1) ? x1 : url_bar->extent.x1, y1); } else { xwimp_force_redraw(url_bar->window, url_bar->extent.x0, url_bar->extent.y0, url_bar->extent.x1, url_bar->extent.y1); xwimp_force_redraw(url_bar->window, x0, y0, x1, y1); } } /* Reposition the URL bar icons. */ url_bar->extent.x0 = x0; url_bar->extent.y0 = y0; url_bar->extent.x1 = x1; url_bar->extent.y1 = y1; return ro_gui_url_bar_icon_resize(url_bar, !stretch); }
void ro_treeview_update_toolbar(void *data) { ro_treeview *tv = (ro_treeview *) data; if (tv != NULL && tv->tb != NULL) { ro_treeview_set_origin(tv, 0, -(ro_toolbar_height(tv->tb))); xwimp_force_redraw(tv->w, 0, tv->extent.y, tv->extent.x, 0); } }
void ro_gui_debugwin_update(void *p) { os_error *error; ro_gui_debugwin_resize(); error = xwimp_force_redraw(dialog_debug, 0, -10000, 10000, 0); if (error) { LOG(("xwimp_force_redraw: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); } schedule(DEBUGWIN_UPDATE, ro_gui_debugwin_update, 0); }
bool ro_gui_url_bar_set_site_favicon(struct url_bar *url_bar, struct hlcache_handle *h) { content_type type = CONTENT_NONE; if (url_bar == NULL) return false; if (h != NULL) type = content_get_type(h); // \TODO -- Maybe test for CONTENT_ICO ??? if (type == CONTENT_IMAGE) { url_bar->favicon_content = h; url_bar->favicon_width = content_get_width(h); url_bar->favicon_height = content_get_height(h); if (url_bar->favicon_width > URLBAR_FAVICON_SIZE) url_bar->favicon_width = URLBAR_FAVICON_SIZE; if (url_bar->favicon_height > URLBAR_FAVICON_SIZE) url_bar->favicon_height = URLBAR_FAVICON_SIZE; url_bar->favicon_offset.x = ((url_bar->favicon_extent.x1 - url_bar->favicon_extent.x0) - (url_bar->favicon_width * 2)) / 2; url_bar->favicon_offset.y = ((url_bar->favicon_extent.y1 - url_bar->favicon_extent.y0) - (url_bar->favicon_height * 2)) / 2; } else { url_bar->favicon_content = NULL; if (url_bar->favicon_type != 0) snprintf(url_bar->favicon_sprite, URLBAR_FAVICON_NAME_LENGTH, "Ssmall_%.3x", url_bar->favicon_type); else snprintf(url_bar->favicon_sprite, URLBAR_FAVICON_NAME_LENGTH, "Ssmall_xxx"); } if (!url_bar->hidden) xwimp_force_redraw(url_bar->window, url_bar->favicon_extent.x0, url_bar->favicon_extent.y0, url_bar->favicon_extent.x1, url_bar->favicon_extent.y1); return true; }
bool ro_gui_url_bar_set_content_favicon(struct url_bar *url_bar, struct hlcache_handle *h) { int type = 0; char sprite[URLBAR_FAVICON_NAME_LENGTH]; if (url_bar == NULL) return false; if (h != NULL) type = ro_content_filetype(h); if (type != 0) { snprintf(sprite, URLBAR_FAVICON_NAME_LENGTH, "small_%.3x", type); if (!ro_gui_wimp_sprite_exists(sprite)) type = 0; } url_bar->favicon_type = type; if (url_bar->favicon_content == NULL) { if (type == 0) snprintf(url_bar->favicon_sprite, URLBAR_FAVICON_NAME_LENGTH, "Ssmall_xxx"); else snprintf(url_bar->favicon_sprite, URLBAR_FAVICON_NAME_LENGTH, "S%s", sprite); if (!url_bar->hidden) xwimp_force_redraw(url_bar->window, url_bar->favicon_extent.x0, url_bar->favicon_extent.y0, url_bar->favicon_extent.x1, url_bar->favicon_extent.y1); } return true; }
void ro_gui_options_theme_load(void) { os_error *error; os_box extent = { 0, 0, 0, 0 }; struct theme_descriptor *descriptor; struct toolbar_display *link; struct toolbar_display *toolbar_display; struct toolbar *toolbar; wimp_icon_create new_icon; wimp_window_state state; int parent_width, nested_y, min_extent, base_extent; int item_height; int *radio_icons, *radio_set; int theme_count; /* delete our old list and get/open a new one */ ro_gui_options_theme_free(); theme_list = ro_gui_theme_get_available(); ro_gui_theme_open(theme_list, true); /* create toolbars for each theme */ theme_count = 0; descriptor = theme_list; while (descriptor) { /* try to create a toolbar */ toolbar = ro_gui_theme_create_toolbar(descriptor, THEME_BROWSER_TOOLBAR); if (toolbar) { toolbar_display = calloc(sizeof(struct toolbar_display), 1); if (!toolbar_display) { LOG(("No memory for calloc()")); warn_user("NoMemory", 0); return; } toolbar_display->toolbar = toolbar; toolbar_display->descriptor = descriptor; if (!toolbars) { toolbars = toolbar_display; } else { link = toolbars; while (link->next) link = link->next; link->next = toolbar_display; } theme_count++; } descriptor = descriptor->next; } /* nest the toolbars */ state.w = theme_pane; 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; } parent_width = state.visible.x1 - state.visible.x0; min_extent = state.visible.y0 - state.visible.y1; nested_y = 0; base_extent = state.visible.y1 - state.yscroll; extent.x1 = parent_width; link = toolbars; new_icon.w = theme_pane; new_icon.icon.flags = wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_VCENTRED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT); while (link) { /* update the toolbar */ item_height = 44 + 44 + 16; if (link->next) item_height += 16; ro_gui_theme_process_toolbar(link->toolbar, parent_width); extent.y0 = nested_y - link->toolbar->height - item_height; if (link->next) extent.y0 -= 16; if (extent.y0 > min_extent) extent.y0 = min_extent; xwimp_set_extent(theme_pane, &extent); ro_gui_set_icon_button_type(link->toolbar->toolbar_handle, ICON_TOOLBAR_URL, wimp_BUTTON_NEVER); /* create the descriptor icons and separator line */ new_icon.icon.extent.x0 = 8; new_icon.icon.extent.x1 = parent_width - 8; new_icon.icon.flags &= ~wimp_ICON_BORDER; new_icon.icon.flags |= wimp_ICON_SPRITE; new_icon.icon.extent.y1 = nested_y - link->toolbar->height - 8; new_icon.icon.extent.y0 = nested_y - link->toolbar->height - 52; new_icon.icon.data.indirected_text_and_sprite.text = (char *)&link->descriptor->name; new_icon.icon.data.indirected_text_and_sprite.size = strlen(link->descriptor->name) + 1; new_icon.icon.data.indirected_text_and_sprite.validation = theme_radio_validation; new_icon.icon.flags |= (wimp_BUTTON_RADIO << wimp_ICON_BUTTON_TYPE_SHIFT); xwimp_create_icon(&new_icon, &link->icon_number); new_icon.icon.flags &= ~wimp_ICON_SPRITE; new_icon.icon.extent.x0 = 52; new_icon.icon.extent.y1 -= 44; new_icon.icon.extent.y0 -= 44; new_icon.icon.data.indirected_text.text = (char *)&link->descriptor->author; new_icon.icon.data.indirected_text.size = strlen(link->descriptor->filename) + 1; new_icon.icon.data.indirected_text.validation = theme_null_validation; new_icon.icon.flags &= ~(wimp_BUTTON_RADIO << wimp_ICON_BUTTON_TYPE_SHIFT); xwimp_create_icon(&new_icon, 0); if (link->next) { new_icon.icon.flags |= wimp_ICON_BORDER; new_icon.icon.extent.x0 = -8; new_icon.icon.extent.x1 = parent_width + 8; new_icon.icon.extent.y1 -= 52; new_icon.icon.extent.y0 = new_icon.icon.extent.y1 - 8; new_icon.icon.data.indirected_text.text = theme_null_validation; new_icon.icon.data.indirected_text.validation = theme_line_validation; new_icon.icon.data.indirected_text.size = 1; xwimp_create_icon(&new_icon, 0); } /* nest the toolbar window */ state.w = link->toolbar->toolbar_handle; state.yscroll = 0; state.visible.y1 = nested_y + base_extent; state.visible.y0 = state.visible.y1 - link->toolbar->height + 2; xwimp_open_window_nested(PTR_WIMP_OPEN(&state), theme_pane, wimp_CHILD_LINKS_PARENT_WORK_AREA << wimp_CHILD_BS_EDGE_SHIFT | wimp_CHILD_LINKS_PARENT_WORK_AREA << wimp_CHILD_TS_EDGE_SHIFT); /* continue processing */ nested_y -= link->toolbar->height + item_height; link = link->next; } /* set the icons as radios */ radio_icons = (int *)calloc(theme_count + 1, sizeof(int)); radio_set = radio_icons; for (link = toolbars; link; link = link->next) *radio_set++ = link->icon_number; *radio_set = -1; ro_gui_wimp_event_register_radio(theme_pane, radio_icons); /* update our display */ xwimp_force_redraw(theme_pane, 0, -16384, 16384, 16384); }
bool ro_gui_url_complete_keypress(struct toolbar *toolbar, uint32_t key) { wimp_w parent; wimp_window_state state; char *match_url; const char *url; int old_selection; int height; os_error *error; bool currently_open; assert(toolbar != NULL); parent = ro_toolbar_get_parent_window(toolbar); /* we must have a toolbar/url bar */ if (!ro_toolbar_get_display_url(toolbar) || (!nsoption_bool(url_suggestion))) { ro_gui_url_complete_close(); return false; } /* if we are currently active elsewhere, remove the previous window */ currently_open = ((parent == url_complete_parent) && (url_complete_matches_available > 0)); if (parent != url_complete_parent) ro_gui_url_complete_close(); /* 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 = parent; url = ro_toolbar_get_url(toolbar); match_url = (url != NULL) ? strdup(url) : NULL; if (match_url == NULL) { ro_gui_url_complete_close(); 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 */ int i; int 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); ro_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(); 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(); return false; } /* update the window */ state.w = parent; 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; } url_complete_matches_reset = true; ro_gui_url_complete_resize(toolbar, 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); ro_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); 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 (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_toolbar_set_url(toolbar, url_complete_original_url, true, false); } else { ro_toolbar_set_url(toolbar, nsurl_access(url_complete_matches[ url_complete_matches_selection]), true, false); free(url_complete_matched_string); url_complete_matched_string = strdup(nsurl_access( 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); ro_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); ro_warn_user("WimpError", error->errmess); return true; } return true; }
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; }