void ro_gui_iconbar_initialise(void) { os_error *error; /* Build the iconbar menu */ static const struct ns_menu iconbar_definition = { "NetSurf", { { "Info", NO_ACTION, &dialog_info }, { "AppHelp", HELP_OPEN_CONTENTS, 0 }, { "Open", BROWSER_NAVIGATE_URL, 0 }, { "Open.OpenURL", BROWSER_NAVIGATE_URL, &dialog_openurl }, { "Open.HotlistShow", HOTLIST_SHOW, 0 }, { "Open.HistGlobal", HISTORY_SHOW_GLOBAL, 0 }, { "Open.ShowCookies", COOKIES_SHOW, 0 }, { "Choices", CHOICES_SHOW, 0 }, { "Quit", APPLICATION_QUIT, 0 }, {NULL, 0, 0} } }; ro_gui_iconbar_menu = ro_gui_menu_define_menu(&iconbar_definition); /* Create an iconbar icon. */ wimp_icon_create icon = { wimp_ICON_BAR_RIGHT, { { 0, 0, 68, 68 }, wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | (wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT), { "!netsurf" } } }; error = xwimp_create_icon(&icon, 0); if (error) { LOG(("xwimp_create_icon: 0x%x: %s", error->errnum, error->errmess)); die(error->errmess); } /* Register handlers to look after clicks and menu actions. */ ro_gui_wimp_event_register_mouse_click(wimp_ICON_BAR, ro_gui_iconbar_click); ro_gui_wimp_event_register_menu(wimp_ICON_BAR, ro_gui_iconbar_menu, true, true); ro_gui_wimp_event_register_menu_selection(wimp_ICON_BAR, ro_gui_iconbar_menu_select); ro_gui_wimp_event_register_menu_warning(wimp_ICON_BAR, ro_gui_iconbar_menu_warning); }
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_bar_icon_update(struct url_bar *url_bar) { wimp_icon_create icon; os_error *error; bool resize; if (url_bar == NULL || url_bar->window == NULL) return false; icon.w = url_bar->window; icon.icon.extent.x0 = 0; icon.icon.extent.y0 = 0; icon.icon.extent.x1 = 0; icon.icon.extent.y1 = 0; resize = false; /* Create or delete the container icon. */ if (!url_bar->hidden && url_bar->container_icon == -1) { icon.icon.flags = wimp_ICON_BORDER | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT); error = xwimp_create_icon(&icon, &url_bar->container_icon); if (error != NULL) { LOG(("xwimp_create_icon: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); url_bar->container_icon = -1; return false; } resize = true; } else if (url_bar->hidden && url_bar->container_icon != -1){ error = xwimp_delete_icon(url_bar->window, url_bar->container_icon); if (error != NULL) { LOG(("xwimp_delete_icon: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return false; } url_bar->container_icon = -1; } /* Create or delete the text icon. */ if (!url_bar->hidden && url_bar->text_icon == -1) { icon.icon.data.indirected_text.text = url_bar->text_buffer; icon.icon.data.indirected_text.validation = text_validation; icon.icon.data.indirected_text.size = url_bar->text_size; icon.icon.flags = wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT); if (url_bar->display) icon.icon.flags |= (wimp_BUTTON_NEVER << wimp_ICON_BUTTON_TYPE_SHIFT); else icon.icon.flags |= (wimp_BUTTON_WRITE_CLICK_DRAG << wimp_ICON_BUTTON_TYPE_SHIFT); error = xwimp_create_icon(&icon, &url_bar->text_icon); if (error) { LOG(("xwimp_create_icon: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); url_bar->text_icon = -1; return false; } resize = true; } else if (url_bar->hidden && url_bar->text_icon != -1) { error = xwimp_delete_icon(url_bar->window, url_bar->text_icon); if (error != NULL) { LOG(("xwimp_delete_icon: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return false; } url_bar->text_icon = -1; } /* Create or delete the suggest icon. */ if (!url_bar->hidden && url_bar->suggest_icon == -1) { icon.icon.data.indirected_text.text = null_text_string; icon.icon.data.indirected_text.size = 1; icon.icon.data.indirected_text.validation = suggest_validation; icon.icon.flags = wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | (wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT); error = xwimp_create_icon(&icon, &url_bar->suggest_icon); if (error) { LOG(("xwimp_create_icon: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return false; } if (!url_bar->display) ro_gui_wimp_event_register_menu_gright(url_bar->window, wimp_ICON_WINDOW, url_bar->suggest_icon, ro_gui_url_suggest_menu); if (!ro_gui_url_bar_update_urlsuggest(url_bar)) return false; resize = true; } else if (url_bar->hidden && url_bar->suggest_icon != -1) { ro_gui_wimp_event_deregister(url_bar->window, url_bar->suggest_icon); error = xwimp_delete_icon(url_bar->window, url_bar->suggest_icon); if (error != NULL) { LOG(("xwimp_delete_icon: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return false; } url_bar->suggest_icon = -1; } /* If any icons were created, resize the bar. */ if (resize && !ro_gui_url_bar_icon_resize(url_bar, true)) return false; /* If there are any icons, apply shading as necessary. */ if (url_bar->container_icon != -1) ro_gui_set_icon_shaded_state(url_bar->window, url_bar->container_icon, url_bar->shaded); if (url_bar->text_icon != -1) ro_gui_set_icon_shaded_state(url_bar->window, url_bar->text_icon, url_bar->shaded); if (url_bar->suggest_icon != -1) ro_gui_set_icon_shaded_state(url_bar->window, url_bar->suggest_icon, url_bar->shaded); return true; }