2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2003-11-20 03:16:31 +03:00
|
|
|
* Copyright 2003 James Bursa <bursa@users.sourceforge.net>
|
2004-05-05 02:23:44 +04:00
|
|
|
* Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
|
2003-06-06 06:14:28 +04:00
|
|
|
*/
|
2002-10-15 14:47:44 +04:00
|
|
|
|
2003-11-20 03:16:31 +03:00
|
|
|
/** \file
|
|
|
|
* Toolbar themes (implementation).
|
|
|
|
*/
|
|
|
|
|
2004-05-02 21:01:37 +04:00
|
|
|
#include <alloca.h>
|
2003-11-20 03:16:31 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2003-06-05 03:47:20 +04:00
|
|
|
#include <string.h>
|
2004-05-05 02:23:44 +04:00
|
|
|
#include "oslib/os.h"
|
2004-05-23 03:04:44 +04:00
|
|
|
#include "oslib/osgbpb.h"
|
2003-11-20 03:16:31 +03:00
|
|
|
#include "oslib/osfile.h"
|
|
|
|
#include "oslib/osspriteop.h"
|
|
|
|
#include "oslib/wimp.h"
|
2004-05-05 02:23:44 +04:00
|
|
|
#include "oslib/wimpspriteop.h"
|
2003-11-20 03:16:31 +03:00
|
|
|
#include "netsurf/riscos/gui.h"
|
|
|
|
#include "netsurf/riscos/theme.h"
|
2004-05-05 02:23:44 +04:00
|
|
|
#include "netsurf/riscos/toolbar.h"
|
|
|
|
#include "netsurf/riscos/wimp.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/utils/utils.h"
|
2004-05-05 02:23:44 +04:00
|
|
|
#include "netsurf/utils/log.h"
|
2002-10-15 14:47:44 +04:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Current sprite area
|
|
|
|
*/
|
2003-11-20 03:16:31 +03:00
|
|
|
static osspriteop_area *theme_sprite_area = 0;
|
2004-05-05 02:23:44 +04:00
|
|
|
|
|
|
|
/* Throbber details
|
|
|
|
*/
|
|
|
|
int theme_throbs;
|
|
|
|
static int throbber_width;
|
|
|
|
static int throbber_height;
|
2002-10-15 14:47:44 +04:00
|
|
|
|
|
|
|
|
2003-11-20 03:16:31 +03:00
|
|
|
/**
|
|
|
|
* Load a theme from a directory.
|
|
|
|
*
|
|
|
|
* The directory must contain a Templates file containing the toolbar template,
|
|
|
|
* and a Sprites file containing icons.
|
|
|
|
*/
|
2002-10-15 14:47:44 +04:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
void ro_theme_load(char *pathname) {
|
|
|
|
osbool mask;
|
|
|
|
os_mode mode;
|
|
|
|
os_coord dimensions;
|
|
|
|
int size, i, n;
|
2004-05-05 04:19:51 +04:00
|
|
|
char *filename = alloca(strlen(pathname) + 16);
|
2003-11-20 03:16:31 +03:00
|
|
|
fileswitch_object_type obj_type;
|
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Release previous sprite are
|
|
|
|
*/
|
2003-11-20 03:16:31 +03:00
|
|
|
free(theme_sprite_area);
|
2004-05-05 02:23:44 +04:00
|
|
|
theme_sprite_area = NULL;
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Reset the throbber variables
|
|
|
|
*/
|
|
|
|
theme_throbs = 0;
|
|
|
|
throbber_height = 0;
|
|
|
|
throbber_width = 0;
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Load the sprites
|
|
|
|
*/
|
|
|
|
sprintf(filename, "%s.Sprites", pathname);
|
|
|
|
xosfile_read_no_path(filename, &obj_type, 0, 0, &size, 0);
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Claim memory for a sprite file if we have one
|
|
|
|
*/
|
|
|
|
if (obj_type & fileswitch_IS_FILE) theme_sprite_area = malloc(size + 16);
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Load the sprite file if we have any memory
|
|
|
|
*/
|
|
|
|
if (theme_sprite_area) {
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Initialise then load
|
|
|
|
*/
|
|
|
|
theme_sprite_area->size = size + 16;
|
|
|
|
theme_sprite_area->sprite_count = 0;
|
|
|
|
theme_sprite_area->first = 16;
|
|
|
|
theme_sprite_area->used = 16;
|
|
|
|
xosspriteop_clear_sprites(osspriteop_USER_AREA, theme_sprite_area);
|
|
|
|
xosspriteop_load_sprite_file(osspriteop_USER_AREA, theme_sprite_area,
|
|
|
|
filename);
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Find the highest sprite called 'throbber%i', and get the maximum
|
|
|
|
dimensions for all 'thobber%i' icons. We use the filename buffer
|
|
|
|
as the temporary spritename buffer as it is guaranteed to be at
|
|
|
|
least 12 bytes (max sprite name size).
|
|
|
|
*/
|
|
|
|
for (i = 1; i <= theme_sprite_area->sprite_count; i++) {
|
|
|
|
osspriteop_return_name(osspriteop_USER_AREA,
|
|
|
|
theme_sprite_area, filename, 12, i);
|
|
|
|
if (strncmp(filename, "throbber", 8) == 0) {
|
|
|
|
/* Get the max sprite width/height
|
|
|
|
*/
|
|
|
|
xosspriteop_read_sprite_info(osspriteop_USER_AREA,
|
|
|
|
theme_sprite_area, (osspriteop_id)filename,
|
|
|
|
&dimensions.x, &dimensions.y, &mask, &mode);
|
|
|
|
ro_convert_pixels_to_os_units(&dimensions, mode);
|
|
|
|
if (dimensions.x > throbber_width) throbber_width = dimensions.x;
|
|
|
|
if (dimensions.y > throbber_height) throbber_height = dimensions.y;
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Get the throbber number
|
|
|
|
*/
|
|
|
|
n = atoi(filename + 8);
|
|
|
|
if (theme_throbs < n) theme_throbs = n;
|
|
|
|
}
|
2003-11-20 03:16:31 +03:00
|
|
|
}
|
|
|
|
}
|
2004-05-05 02:23:44 +04:00
|
|
|
|
2002-10-15 14:47:44 +04:00
|
|
|
}
|
|
|
|
|
2003-06-05 03:47:20 +04:00
|
|
|
|
2003-11-20 03:16:31 +03:00
|
|
|
/**
|
2004-07-08 02:09:26 +04:00
|
|
|
* Create a toolbar from the current theme for a browser window.
|
2003-11-20 03:16:31 +03:00
|
|
|
*
|
|
|
|
* The buffers url_buffer and status_buffer must be at least 256 bytes each,
|
|
|
|
* throbber_buffer at least 12 bytes;
|
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
void ro_theme_create_browser_toolbar(gui_window *g) {
|
2004-05-05 02:23:44 +04:00
|
|
|
struct toolbar *toolbar;
|
2002-10-15 14:47:44 +04:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Destroy any previous toolbar (paranoia)
|
|
|
|
*/
|
|
|
|
if (g->data.browser.toolbar) {
|
|
|
|
ro_toolbar_destroy(g->data.browser.toolbar);
|
|
|
|
g->data.browser.toolbar = NULL;
|
|
|
|
}
|
|
|
|
/* Create a toolbar
|
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
toolbar = ro_toolbar_create(theme_sprite_area, g->url, g->status,
|
|
|
|
g->throb_buf, TOOLBAR_BROWSER);
|
2004-05-05 02:23:44 +04:00
|
|
|
if (toolbar == NULL) return;
|
|
|
|
|
|
|
|
/* Set up the throbber
|
|
|
|
*/
|
|
|
|
toolbar->throbber_width = throbber_width;
|
|
|
|
toolbar->throbber_height = throbber_height;
|
|
|
|
toolbar->status_width = 640;
|
|
|
|
|
|
|
|
/* Store our toolbar
|
|
|
|
*/
|
|
|
|
g->data.browser.toolbar = toolbar;
|
2002-10-15 14:47:44 +04:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Update the toolbar
|
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
ro_theme_update_toolbar(toolbar, g->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a toolbar from the current theme for a hotlist window.
|
|
|
|
*
|
|
|
|
* The buffers url_buffer and status_buffer must be at least 256 bytes each,
|
|
|
|
* throbber_buffer at least 12 bytes;
|
|
|
|
*/
|
|
|
|
void ro_theme_create_hotlist_toolbar(void) {
|
|
|
|
struct toolbar *toolbar;
|
|
|
|
|
|
|
|
/* Destroy any previous toolbar (paranoia)
|
|
|
|
*/
|
|
|
|
if (hotlist_toolbar) {
|
|
|
|
ro_toolbar_destroy(hotlist_toolbar);
|
|
|
|
hotlist_toolbar = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a toolbar
|
|
|
|
*/
|
|
|
|
toolbar = ro_toolbar_create(theme_sprite_area, NULL, NULL,
|
|
|
|
NULL, TOOLBAR_HOTLIST);
|
|
|
|
if (toolbar == NULL) return;
|
|
|
|
|
|
|
|
/* Store our toolbar
|
|
|
|
*/
|
|
|
|
hotlist_toolbar = toolbar;
|
|
|
|
|
|
|
|
/* Update the toolbar
|
|
|
|
*/
|
|
|
|
ro_theme_update_toolbar(toolbar, hotlist_window);
|
2002-10-15 14:47:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-08 02:09:26 +04:00
|
|
|
|
2003-11-20 03:16:31 +03:00
|
|
|
/**
|
2004-05-05 02:23:44 +04:00
|
|
|
* Updates any toolbar flags (eg closes windows, hides icons etc)
|
|
|
|
*
|
|
|
|
* \return non-zero if the toolbar height has changed
|
2003-11-20 03:16:31 +03:00
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
int ro_theme_update_toolbar(struct toolbar *toolbar, wimp_w window) {
|
2004-05-05 02:23:44 +04:00
|
|
|
wimp_outline outline;
|
|
|
|
wimp_window_state state;
|
|
|
|
int return_value = 0;
|
|
|
|
|
|
|
|
/* Set an update as pending
|
|
|
|
*/
|
|
|
|
toolbar->update_pending = true;
|
|
|
|
|
|
|
|
/* Close the status window if we should, or resize it
|
|
|
|
*/
|
|
|
|
if (toolbar->status_window) {
|
2002-10-15 14:47:44 +04:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Update the status height
|
2004-07-08 02:09:26 +04:00
|
|
|
*/
|
|
|
|
ro_toolbar_resize_status(toolbar, ro_get_hscroll_height(window) - 2);
|
2004-05-05 02:23:44 +04:00
|
|
|
} else {
|
|
|
|
xwimp_close_window(toolbar->status_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the toolbar height
|
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
return_value = ro_theme_resize_toolbar(toolbar, window);
|
2004-05-05 02:23:44 +04:00
|
|
|
|
|
|
|
/* Open/close the toolbar
|
|
|
|
*/
|
|
|
|
if (toolbar->height > 0) {
|
2004-07-08 02:09:26 +04:00
|
|
|
outline.w = window;
|
2004-05-05 02:23:44 +04:00
|
|
|
xwimp_get_window_outline(&outline);
|
2004-07-08 02:09:26 +04:00
|
|
|
state.w = window;
|
2004-05-05 02:23:44 +04:00
|
|
|
xwimp_get_window_state(&state);
|
|
|
|
state.w = toolbar->toolbar_handle;
|
|
|
|
state.visible.x1 = outline.outline.x1 - 2;
|
2004-07-10 01:03:26 +04:00
|
|
|
state.visible.y0 = state.visible.y1 - toolbar->height + 2;
|
2004-05-05 02:23:44 +04:00
|
|
|
state.xscroll = 0;
|
|
|
|
state.yscroll = 0;
|
|
|
|
state.next = wimp_TOP;
|
2004-07-08 02:09:26 +04:00
|
|
|
xwimp_open_window_nested((wimp_open *)&state, window,
|
2004-05-05 02:23:44 +04:00
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
xwimp_close_window(toolbar->toolbar_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return
|
|
|
|
*/
|
|
|
|
return return_value;
|
2002-10-15 14:47:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-20 03:16:31 +03:00
|
|
|
/**
|
2004-05-05 02:23:44 +04:00
|
|
|
* Resize the status and toolbar windows.
|
|
|
|
*
|
|
|
|
* \return non-zero if the toolbar height has changed
|
2003-11-20 03:16:31 +03:00
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
int ro_theme_resize_toolbar(struct toolbar *toolbar, wimp_w window) {
|
2004-05-05 02:23:44 +04:00
|
|
|
os_box extent = { 0, 0, 0, 0 };
|
|
|
|
wimp_outline outline;
|
|
|
|
wimp_outline status_outline;
|
|
|
|
wimp_window_state state;
|
|
|
|
int width, status_width;
|
|
|
|
int return_value = 0;
|
|
|
|
|
|
|
|
/* Paranoia
|
|
|
|
*/
|
|
|
|
if (toolbar == NULL) return 0;
|
2002-10-15 14:47:44 +04:00
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Get the toolbar width
|
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
outline.w = window;
|
2004-05-05 02:23:44 +04:00
|
|
|
if (xwimp_get_window_outline(&outline)) return 0;
|
|
|
|
width = outline.outline.x1 - outline.outline.x0 - 2;
|
|
|
|
|
|
|
|
/* Reformat if we should
|
|
|
|
*/
|
|
|
|
if ((toolbar->width != width) || (toolbar->resize_status) || (toolbar->update_pending)) {
|
2004-07-08 02:09:26 +04:00
|
|
|
if ((toolbar->resize_status) && (toolbar->status_handle)) {
|
2004-05-05 02:23:44 +04:00
|
|
|
status_outline.w = toolbar->status_handle;
|
|
|
|
if (xwimp_get_window_outline(&status_outline)) return 0;
|
|
|
|
toolbar->status_width = width -
|
|
|
|
(status_outline.outline.x1 - status_outline.outline.x0 - 4);
|
|
|
|
toolbar->resize_status = 0;
|
2004-07-08 02:09:26 +04:00
|
|
|
} else if (toolbar->status_handle) {
|
2004-05-05 02:23:44 +04:00
|
|
|
/* Update the extent of the status window
|
|
|
|
*/
|
2004-07-08 02:09:26 +04:00
|
|
|
state.w = window;
|
2004-05-05 02:23:44 +04:00
|
|
|
if (xwimp_get_window_state(&state)) return 0;
|
|
|
|
extent.x1 = state.visible.x1 - state.visible.x0;
|
|
|
|
extent.y1 = toolbar->status_height - 2;
|
|
|
|
xwimp_set_extent(toolbar->status_handle, &extent);
|
|
|
|
|
|
|
|
/* Re-open the status window as we can't use the nested
|
|
|
|
wimp to manage everything as it would keep extending
|
|
|
|
the size incorrectly.
|
|
|
|
*/
|
|
|
|
status_width = width - toolbar->status_width;
|
|
|
|
if (status_width < 12) status_width = 12;
|
|
|
|
if (toolbar->status_window) {
|
|
|
|
state.w = toolbar->status_handle;
|
|
|
|
state.xscroll = 0;
|
|
|
|
state.yscroll = 0;
|
|
|
|
state.next = wimp_TOP;
|
|
|
|
state.visible.x0 = outline.outline.x0;
|
|
|
|
state.visible.x1 = outline.outline.x0 + status_width;
|
|
|
|
state.visible.y0 = outline.outline.y0 - toolbar->status_height;
|
|
|
|
state.visible.y1 = outline.outline.y0 - 2;
|
2004-07-08 02:09:26 +04:00
|
|
|
xwimp_open_window_nested((wimp_open *) &state, window,
|
2004-05-05 02:23:44 +04:00
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
|
|
|
|
<< wimp_CHILD_XORIGIN_SHIFT |
|
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
|
|
|
|
<< wimp_CHILD_YORIGIN_SHIFT |
|
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
|
|
|
|
<< wimp_CHILD_LS_EDGE_SHIFT |
|
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
|
|
|
|
<< wimp_CHILD_BS_EDGE_SHIFT |
|
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT
|
|
|
|
<< wimp_CHILD_RS_EDGE_SHIFT |
|
|
|
|
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
|
|
|
|
<< wimp_CHILD_TS_EDGE_SHIFT);
|
|
|
|
} else {
|
|
|
|
if (toolbar->update_pending) {
|
|
|
|
xwimp_close_window(toolbar->status_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize the toolbar
|
|
|
|
*/
|
|
|
|
return ro_toolbar_reformat(toolbar, width);
|
|
|
|
}
|
|
|
|
return return_value;
|
2002-10-15 14:47:44 +04:00
|
|
|
}
|
2004-05-23 03:04:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a list of available themes.
|
|
|
|
*
|
|
|
|
* \param entries updated to number of themes
|
|
|
|
* \return array of struct theme_entry, or 0 on error, and error reported
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct theme_entry *ro_theme_list(unsigned int *entries)
|
|
|
|
{
|
|
|
|
char pathname[256];
|
|
|
|
unsigned int i = 0, n = 0;
|
|
|
|
int context = 0;
|
|
|
|
int read_count;
|
|
|
|
struct theme_entry *list = 0, *list1;
|
|
|
|
fileswitch_object_type obj_type;
|
|
|
|
int file_type;
|
|
|
|
osgbpb_INFO(100) info;
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
/* invariant: list[0..n) are valid */
|
|
|
|
while (context != -1) {
|
|
|
|
error = xosgbpb_dir_entries_info(THEMES_DIR,
|
|
|
|
(osgbpb_info_list *) &info, 1, context,
|
|
|
|
sizeof(info), 0, &read_count, &context);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosgbpb_dir_entries_info: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MiscError", error->errmess);
|
|
|
|
ro_theme_list_free(list, n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read_count == 0)
|
|
|
|
continue;
|
|
|
|
if (info.obj_type != fileswitch_IS_DIR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check for presence of Sprites in directory */
|
|
|
|
snprintf(pathname, sizeof pathname, "%s.%s.%s",
|
|
|
|
THEMES_DIR, info.name, "Sprites");
|
|
|
|
pathname[sizeof pathname - 1] = 0;
|
|
|
|
error = xosfile_read_stamped_no_path(pathname,
|
|
|
|
&obj_type, 0, 0, 0, 0, &file_type);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosfile_read_stamped_no_path: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MiscError", error->errmess);
|
|
|
|
ro_theme_list_free(list, n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (obj_type != fileswitch_IS_FILE ||
|
|
|
|
file_type != osfile_TYPE_SPRITE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* expand list */
|
|
|
|
list1 = realloc(list, sizeof *list * (i + 1));
|
|
|
|
if (!list1) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
ro_theme_list_free(list, n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
list = list1;
|
|
|
|
|
|
|
|
/* update invariant */
|
|
|
|
list[i].name = 0;
|
|
|
|
list[i].sprite_area = 0;
|
|
|
|
n = i + 1;
|
|
|
|
|
|
|
|
/* copy name */
|
|
|
|
list[i].name = strdup(info.name);
|
|
|
|
if (!list[i].name) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
ro_theme_list_free(list, n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load sprites */
|
|
|
|
list[i].sprite_area = ro_gui_load_sprite_file(pathname);
|
|
|
|
if (!list[i].sprite_area) {
|
|
|
|
ro_theme_list_free(list, n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*entries = n;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free an array of themes, as returned by ro_theme_list().
|
|
|
|
*
|
|
|
|
* \param list array of struct theme_entry
|
|
|
|
* \param entries size of array
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_theme_list_free(struct theme_entry *list, unsigned int entries)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i != entries; i++) {
|
|
|
|
free(list[i].name);
|
|
|
|
free(list[i].sprite_area);
|
|
|
|
}
|
|
|
|
free(list);
|
|
|
|
}
|