bool ro_gui_theme_install_apply(wimp_w w) { char theme_save[256]; char *theme_file; struct theme_descriptor *theme_install; os_error *error; char *fix; const char *source_data; unsigned long source_size; assert(theme_install_content); /* convert spaces to hard spaces */ theme_file = strdup(theme_install_descriptor.name); if (!theme_file) { LOG(("malloc failed")); warn_user("NoMemory", 0); return false; } for (fix = theme_file; *fix != '\0'; fix++) if (*fix == ' ') *fix = 160; /* hard space */ /* simply overwrite previous theme versions */ snprintf(theme_save, sizeof theme_save, "%s.%s", nsoption_charp(theme_save), theme_file); theme_save[sizeof theme_save - 1] = '\0'; source_data = content_get_source_data(theme_install_content, &source_size); error = xosfile_save_stamped(theme_save, 0xffd, (byte *) source_data, (byte *) source_data + source_size); if (error) { LOG(("xosfile_save_stamped: 0x%x: %s", error->errnum, error->errmess)); warn_user("ThemeInstallErr", 0); free(theme_file); return false; } /* apply the new theme */ ro_gui_theme_get_available(); theme_install = ro_gui_theme_find(theme_file); if (!theme_install || !ro_gui_theme_apply(theme_install)) { warn_user("ThemeApplyErr", 0); } else { nsoption_set_charp(theme, strdup(theme_install->leafname)); } free(theme_file); ro_gui_save_options(); return true; }
bool ro_gui_options_theme_click(wimp_pointer *pointer) { struct theme_descriptor *theme_default; struct toolbar_display *toolbar; switch (pointer->i) { case THEME_DEFAULT_BUTTON: theme_default = ro_gui_theme_find("Aletheia"); for (toolbar = toolbars; toolbar; toolbar = toolbar->next) ro_gui_set_icon_selected_state(theme_pane, toolbar->icon_number, (toolbar->descriptor == theme_default)); break; case THEME_CANCEL_BUTTON: ro_gui_wimp_event_restore(theme_pane); break; case THEME_OK_BUTTON: ro_gui_wimp_event_memorise(theme_pane); break; } return false; }
bool ro_gui_options_theme_initialise(wimp_w w) { wimp_window_state state; wimp_icon_state icon_state; os_error *error; struct theme_descriptor *theme_choice; struct toolbar_display *toolbar; /* only allow one instance for now*/ if (theme_pane) return false; error = xwimp_create_window(&theme_pane_definition, &theme_pane); if (error) { LOG(("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess)); return false; } state.w = w; error = xwimp_get_window_state(&state); if (error) { LOG(("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess)); return false; } icon_state.w = w; icon_state.i = THEME_PANE_AREA; error = xwimp_get_icon_state(&icon_state); if (error) { LOG(("xwimp_get_icon_state: 0x%x: %s", error->errnum, error->errmess)); return false; } state.w = theme_pane; state.visible.x1 = state.visible.x0 + icon_state.icon.extent.x1 - 16 - ro_get_vscroll_width(theme_pane); state.visible.x0 += icon_state.icon.extent.x0 + 16; state.visible.y0 = state.visible.y1 + icon_state.icon.extent.y0 + 16; state.visible.y1 += icon_state.icon.extent.y1 - 28; LOG(("Y0 = %i, y1 = %i", icon_state.icon.extent.y0, icon_state.icon.extent.y1)); error = xwimp_open_window_nested(PTR_WIMP_OPEN(&state), w, wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT << wimp_CHILD_XORIGIN_SHIFT | wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT << wimp_CHILD_YORIGIN_SHIFT | wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT << wimp_CHILD_LS_EDGE_SHIFT | wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT << wimp_CHILD_BS_EDGE_SHIFT | wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT << wimp_CHILD_RS_EDGE_SHIFT | wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT << wimp_CHILD_TS_EDGE_SHIFT); if (error) { LOG(("xwimp_open_window_nested: 0x%x: %s", error->errnum, error->errmess)); return false; } /* load themes */ ro_gui_options_theme_load(); /* set the current selection */ theme_choice = ro_gui_theme_find(option_theme); if (!theme_choice) theme_choice = ro_gui_theme_find("Aletheia"); for (toolbar = toolbars; toolbar; toolbar = toolbar->next) ro_gui_set_icon_selected_state(theme_pane, toolbar->icon_number, (toolbar->descriptor == theme_choice)); ro_gui_wimp_event_memorise(theme_pane); ro_gui_wimp_event_set_help_prefix(theme_pane, "HelpThemePConfig"); ro_gui_wimp_event_register_mouse_click(w, ro_gui_options_theme_click); ro_gui_wimp_event_register_cancel(w, THEME_CANCEL_BUTTON); ro_gui_wimp_event_register_ok(w, THEME_OK_BUTTON, ro_gui_options_theme_ok); ro_gui_wimp_event_set_help_prefix(w, "HelpThemeConfig"); ro_gui_wimp_event_memorise(w); return true; }