2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2005-01-23 19:09:05 +03:00
|
|
|
* Copyright 2004, 2005 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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
|
2011-02-21 02:16:33 +03:00
|
|
|
* Window themes (implementation).
|
2003-11-20 03:16:31 +03:00
|
|
|
*/
|
|
|
|
|
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>
|
2004-08-31 01:03:48 +04:00
|
|
|
#include <stdbool.h>
|
2003-06-05 03:47:20 +04:00
|
|
|
#include <string.h>
|
2005-03-20 22:28:50 +03:00
|
|
|
#include "oslib/dragasprite.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"
|
2004-09-08 03:05:34 +04:00
|
|
|
#include "oslib/osfind.h"
|
2008-07-27 02:29:15 +04:00
|
|
|
#include "oslib/osspriteop.h"
|
2005-02-07 17:28:43 +03:00
|
|
|
#include "oslib/wimpspriteop.h"
|
2004-09-08 03:05:34 +04:00
|
|
|
#include "oslib/squash.h"
|
2003-11-20 03:16:31 +03:00
|
|
|
#include "oslib/wimp.h"
|
2004-08-31 01:03:48 +04:00
|
|
|
#include "oslib/wimpextend.h"
|
2004-05-05 02:23:44 +04:00
|
|
|
#include "oslib/wimpspriteop.h"
|
2014-10-16 12:50:55 +04:00
|
|
|
|
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utils.h"
|
2010-04-07 21:46:19 +04:00
|
|
|
#include "content/content.h"
|
2014-10-16 12:50:55 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/cookies.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/dialog.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/global_history.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/gui.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/hotlist.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/menus.h"
|
|
|
|
#include "riscos/theme.h"
|
|
|
|
#include "riscos/treeview.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
2009-03-28 03:56:29 +03:00
|
|
|
#include "riscos/wimputils.h"
|
2004-08-31 01:03:48 +04:00
|
|
|
|
2014-10-16 12:50:55 +04:00
|
|
|
/** @todo provide a proper interface for these and make them static again! */
|
2004-08-31 01:03:48 +04:00
|
|
|
|
|
|
|
static struct theme_descriptor *theme_current = NULL;
|
|
|
|
static struct theme_descriptor *theme_descriptors = NULL;
|
2005-03-21 17:48:26 +03:00
|
|
|
|
2006-01-06 18:36:09 +03:00
|
|
|
static bool ro_gui_theme_add_descriptor(const char *folder, const char *leafname);
|
2005-01-23 19:09:05 +03:00
|
|
|
static void ro_gui_theme_get_available_in_dir(const char *directory);
|
2005-04-10 02:37:09 +04:00
|
|
|
static void ro_gui_theme_free(struct theme_descriptor *descriptor);
|
2004-08-09 00:16:17 +04:00
|
|
|
|
|
|
|
/**
|
2004-08-31 01:03:48 +04:00
|
|
|
* Initialise the theme handler
|
2004-08-09 00:16:17 +04:00
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_theme_initialise(void)
|
|
|
|
{
|
2006-01-06 18:36:09 +03:00
|
|
|
struct theme_descriptor *descriptor;
|
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
theme_descriptors = ro_gui_theme_get_available();
|
2012-03-22 13:34:34 +04:00
|
|
|
descriptor = ro_gui_theme_find(nsoption_charp(theme));
|
2006-01-06 18:36:09 +03:00
|
|
|
if (!descriptor)
|
|
|
|
descriptor = ro_gui_theme_find("Aletheia");
|
|
|
|
ro_gui_theme_apply(descriptor);
|
2004-08-31 01:03:48 +04:00
|
|
|
}
|
2004-08-09 11:07:20 +04:00
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finalise the theme handler
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_theme_finalise(void)
|
|
|
|
{
|
2004-08-31 01:03:48 +04:00
|
|
|
ro_gui_theme_close(theme_current, false);
|
2005-04-10 02:37:09 +04:00
|
|
|
ro_gui_theme_free(theme_descriptors);
|
2004-08-31 01:03:48 +04:00
|
|
|
}
|
2004-08-09 00:16:17 +04:00
|
|
|
|
2004-08-09 11:07:20 +04:00
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
/**
|
|
|
|
* Finds a theme from the cached values.
|
|
|
|
*
|
|
|
|
* The returned theme is only guaranteed to be valid until the next call
|
|
|
|
* to ro_gui_theme_get_available() unless it has been opened using
|
|
|
|
* ro_gui_theme_open().
|
|
|
|
*
|
2005-02-08 02:00:09 +03:00
|
|
|
* \param leafname the filename of the theme_descriptor to return
|
2004-08-31 01:03:48 +04:00
|
|
|
* \return the requested theme_descriptor, or NULL if not found
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
struct theme_descriptor *ro_gui_theme_find(const char *leafname)
|
|
|
|
{
|
2004-08-31 01:03:48 +04:00
|
|
|
struct theme_descriptor *descriptor;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-02-08 02:00:09 +03:00
|
|
|
if (!leafname)
|
|
|
|
return NULL;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
for (descriptor = theme_descriptors; descriptor;
|
|
|
|
descriptor = descriptor->next)
|
|
|
|
if (!strcmp(leafname, descriptor->leafname))
|
2005-02-08 02:00:09 +03:00
|
|
|
return descriptor;
|
2005-05-18 03:46:36 +04:00
|
|
|
/* fallback for 10 chars on old filesystems */
|
|
|
|
for (descriptor = theme_descriptors; descriptor;
|
|
|
|
descriptor = descriptor->next)
|
|
|
|
if (!strncmp(leafname, descriptor->leafname, 10))
|
|
|
|
return descriptor;
|
2004-08-31 01:03:48 +04:00
|
|
|
return NULL;
|
2004-08-09 00:16:17 +04:00
|
|
|
}
|
2002-10-15 14:47:44 +04:00
|
|
|
|
|
|
|
|
2003-11-20 03:16:31 +03:00
|
|
|
/**
|
2004-08-31 01:03:48 +04:00
|
|
|
* Reads and caches the currently available themes.
|
2003-11-20 03:16:31 +03:00
|
|
|
*
|
2004-08-31 01:03:48 +04:00
|
|
|
* \return the requested theme_descriptor, or NULL if not found
|
2003-11-20 03:16:31 +03:00
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
struct theme_descriptor *ro_gui_theme_get_available(void)
|
|
|
|
{
|
2004-08-31 01:03:48 +04:00
|
|
|
struct theme_descriptor *current;
|
|
|
|
struct theme_descriptor *test;
|
2005-01-23 19:09:05 +03:00
|
|
|
|
2006-01-25 03:21:26 +03:00
|
|
|
/* close any unused descriptors */
|
2005-04-10 02:37:09 +04:00
|
|
|
ro_gui_theme_free(theme_descriptors);
|
2006-01-07 16:12:58 +03:00
|
|
|
|
2006-01-25 03:21:26 +03:00
|
|
|
/* add our default 'Aletheia' theme */
|
|
|
|
ro_gui_theme_add_descriptor("NetSurf:Resources", "Aletheia");
|
2006-01-06 18:36:09 +03:00
|
|
|
|
|
|
|
/* scan our choices directory */
|
2012-03-22 13:34:34 +04:00
|
|
|
ro_gui_theme_get_available_in_dir(nsoption_charp(theme_path));
|
2005-01-23 19:09:05 +03:00
|
|
|
|
2006-01-06 18:36:09 +03:00
|
|
|
/* sort alphabetically in a very rubbish way */
|
2005-01-23 19:09:05 +03:00
|
|
|
if ((theme_descriptors) && (theme_descriptors->next)) {
|
|
|
|
current = theme_descriptors;
|
|
|
|
while ((test = current->next)) {
|
|
|
|
if (strcmp(current->name, test->name) > 0) {
|
|
|
|
current->next->previous = current->previous;
|
|
|
|
if (current->previous)
|
|
|
|
current->previous->next = current->next;
|
|
|
|
current->next = test->next;
|
|
|
|
test->next = current;
|
|
|
|
current->previous = test;
|
|
|
|
if (current->next)
|
|
|
|
current->next->previous = current;
|
|
|
|
|
|
|
|
current = test->previous;
|
|
|
|
if (!current) current = test;
|
|
|
|
} else {
|
|
|
|
current = current->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (theme_descriptors->previous)
|
|
|
|
theme_descriptors = theme_descriptors->previous;
|
|
|
|
}
|
2006-01-07 16:12:58 +03:00
|
|
|
|
2005-01-23 19:09:05 +03:00
|
|
|
return theme_descriptors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the themes in a directory to the global cache.
|
|
|
|
*
|
|
|
|
* \param directory the directory to scan
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
static void ro_gui_theme_get_available_in_dir(const char *directory)
|
|
|
|
{
|
2004-08-31 01:03:48 +04:00
|
|
|
int context = 0;
|
|
|
|
int read_count;
|
|
|
|
osgbpb_INFO(100) info;
|
2004-08-09 11:07:20 +04:00
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
while (context != -1) {
|
2006-01-06 18:36:09 +03:00
|
|
|
/* read some directory info */
|
2014-05-31 02:04:10 +04:00
|
|
|
os_error *error = xosgbpb_dir_entries_info(directory,
|
2004-08-31 01:03:48 +04:00
|
|
|
(osgbpb_info_list *) &info, 1, context,
|
|
|
|
sizeof(info), 0, &read_count, &context);
|
|
|
|
if (error) {
|
2015-05-28 19:06:18 +03:00
|
|
|
LOG("xosgbpb_dir_entries_info: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess);
|
2005-01-23 19:09:05 +03:00
|
|
|
if (error->errnum == 0xd6) /* no such dir */
|
|
|
|
return;
|
2004-08-31 01:03:48 +04:00
|
|
|
warn_user("MiscError", error->errmess);
|
|
|
|
break;
|
|
|
|
}
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2006-01-06 18:36:09 +03:00
|
|
|
/* only process files */
|
|
|
|
if ((read_count != 0) && (info.obj_type == fileswitch_IS_FILE))
|
|
|
|
ro_gui_theme_add_descriptor(directory, info.name);
|
|
|
|
}
|
|
|
|
}
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-01-23 19:09:05 +03:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
/**
|
|
|
|
* Returns the current theme handle, or NULL if none is set.
|
|
|
|
*
|
|
|
|
* \return The theme descriptor handle, or NULL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct theme_descriptor *ro_gui_theme_get_current(void)
|
|
|
|
{
|
|
|
|
return theme_current;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a sprite area for use with the given theme. This may return a
|
|
|
|
* pointer to the wimp sprite pool if a theme area isn't available.
|
|
|
|
*
|
|
|
|
* \param *descriptor The theme to use, or NULL for the current.
|
|
|
|
* \return A pointer to the theme sprite area.
|
|
|
|
*/
|
|
|
|
|
|
|
|
osspriteop_area *ro_gui_theme_get_sprites(struct theme_descriptor *descriptor)
|
|
|
|
{
|
|
|
|
osspriteop_area *area;
|
|
|
|
|
|
|
|
if (descriptor == NULL)
|
|
|
|
descriptor = theme_current;
|
|
|
|
|
|
|
|
if (descriptor != NULL && descriptor->theme != NULL)
|
|
|
|
area = descriptor->theme->sprite_area;
|
|
|
|
else
|
|
|
|
area = (osspriteop_area *) 1;
|
|
|
|
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an interger element from the specified theme, or the current theme
|
|
|
|
* if the descriptor is NULL.
|
|
|
|
*
|
|
|
|
* This is an attempt to abstract the theme data from its clients: it should
|
|
|
|
* simplify the task of expanding the theme system in the future should this
|
|
|
|
* be necessary to include other parts of the RISC OS GUI in the theme system.
|
|
|
|
*
|
|
|
|
* \param *descriptor The theme to use, or NULL for the current.
|
|
|
|
* \param style The style to use.
|
|
|
|
* \param element The style element to return.
|
|
|
|
* \return The requested value, or 0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ro_gui_theme_get_style_element(struct theme_descriptor *descriptor,
|
|
|
|
theme_style style, theme_element element)
|
|
|
|
{
|
|
|
|
if (descriptor == NULL)
|
|
|
|
descriptor = theme_current;
|
|
|
|
|
|
|
|
if (descriptor == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (style) {
|
|
|
|
case THEME_STYLE_NONE:
|
|
|
|
switch(element) {
|
|
|
|
case THEME_ELEMENT_FOREGROUND:
|
|
|
|
return wimp_COLOUR_BLACK;
|
|
|
|
case THEME_ELEMENT_BACKGROUND:
|
|
|
|
return wimp_COLOUR_VERY_LIGHT_GREY;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case THEME_STYLE_BROWSER_TOOLBAR:
|
|
|
|
switch (element) {
|
|
|
|
case THEME_ELEMENT_FOREGROUND:
|
|
|
|
return wimp_COLOUR_BLACK;
|
|
|
|
case THEME_ELEMENT_BACKGROUND:
|
|
|
|
return descriptor->browser_background;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case THEME_STYLE_HOTLIST_TOOLBAR:
|
|
|
|
case THEME_STYLE_COOKIES_TOOLBAR:
|
|
|
|
case THEME_STYLE_GLOBAL_HISTORY_TOOLBAR:
|
|
|
|
switch (element) {
|
|
|
|
case THEME_ELEMENT_FOREGROUND:
|
|
|
|
return wimp_COLOUR_BLACK;
|
|
|
|
case THEME_ELEMENT_BACKGROUND:
|
|
|
|
return descriptor->hotlist_background;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case THEME_STYLE_STATUS_BAR:
|
|
|
|
switch (element) {
|
|
|
|
case THEME_ELEMENT_FOREGROUND:
|
|
|
|
return descriptor->status_foreground;
|
|
|
|
case THEME_ELEMENT_BACKGROUND:
|
|
|
|
return descriptor->status_background;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns details of the throbber as defined in a theme.
|
|
|
|
*
|
|
|
|
* \param *descriptor The theme of interest (NULL for current).
|
|
|
|
* \param *frames Return the number of animation frames.
|
|
|
|
* \param *width Return the throbber width.
|
|
|
|
* \param *height Return the throbber height.
|
|
|
|
* \param *right Return the 'locate on right' flag.
|
|
|
|
* \param *redraw Return the 'forcible redraw' flag.
|
|
|
|
* \return true if meaningful data has been returned;
|
|
|
|
* else false.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ro_gui_theme_get_throbber_data(struct theme_descriptor *descriptor,
|
|
|
|
int *frames, int *width, int *height,
|
|
|
|
bool *right, bool *redraw)
|
|
|
|
{
|
|
|
|
if (descriptor == NULL)
|
|
|
|
descriptor = theme_current;
|
|
|
|
|
|
|
|
if (descriptor == NULL || descriptor->theme == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (frames != NULL)
|
|
|
|
*frames = descriptor->theme->throbber_frames;
|
|
|
|
if (width != NULL)
|
|
|
|
*width = descriptor->theme->throbber_width;
|
|
|
|
if (height != NULL)
|
|
|
|
*height = descriptor->theme->throbber_height;
|
|
|
|
if (right != NULL)
|
|
|
|
*right = descriptor->throbber_right;
|
|
|
|
if (redraw != NULL)
|
|
|
|
*redraw = descriptor->throbber_redraw;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-06 18:36:09 +03:00
|
|
|
/**
|
|
|
|
* Checks a theme is valid and adds it to the current list
|
|
|
|
*
|
|
|
|
* \param folder the theme folder
|
|
|
|
* \param leafname the theme leafname
|
|
|
|
* \return whether the theme was added
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
bool ro_gui_theme_add_descriptor(const char *folder, const char *leafname)
|
|
|
|
{
|
2006-01-06 18:36:09 +03:00
|
|
|
struct theme_file_header file_header;
|
|
|
|
struct theme_descriptor *current;
|
2006-01-25 03:21:26 +03:00
|
|
|
struct theme_descriptor *test;
|
2006-01-06 18:36:09 +03:00
|
|
|
int output_left;
|
|
|
|
os_fw file_handle;
|
|
|
|
os_error *error;
|
|
|
|
char *filename;
|
2006-01-07 16:12:58 +03:00
|
|
|
|
2006-01-06 18:36:09 +03:00
|
|
|
/* create a full filename */
|
|
|
|
filename = malloc(strlen(folder) + strlen(leafname) + 2);
|
|
|
|
if (!filename) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("No memory for malloc");
|
2006-01-06 18:36:09 +03:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sprintf(filename, "%s.%s", folder, leafname);
|
|
|
|
|
|
|
|
/* get the header */
|
|
|
|
error = xosfind_openinw(osfind_NO_PATH, filename, 0,
|
|
|
|
&file_handle);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosfind_openinw: 0x%x: %s", error->errnum, error->errmess);
|
2006-01-06 18:36:09 +03:00
|
|
|
warn_user("FileError", error->errmess);
|
|
|
|
free(filename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (file_handle == 0) {
|
|
|
|
free(filename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
error = xosgbpb_read_atw(file_handle,
|
2009-03-27 04:29:05 +03:00
|
|
|
(byte *) &file_header,
|
2006-01-06 18:36:09 +03:00
|
|
|
sizeof (struct theme_file_header),
|
|
|
|
0, &output_left);
|
|
|
|
xosfind_closew(file_handle);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosbgpb_read_atw: 0x%x: %s", error->errnum, error->errmess);
|
2006-01-06 18:36:09 +03:00
|
|
|
warn_user("FileError", error->errmess);
|
|
|
|
free(filename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (output_left > 0) { /* should try to read more? */
|
|
|
|
free(filename);
|
|
|
|
return false;
|
|
|
|
}
|
2005-01-23 19:09:05 +03:00
|
|
|
|
2006-01-06 18:36:09 +03:00
|
|
|
/* create a new theme descriptor */
|
|
|
|
current = (struct theme_descriptor *)calloc(1,
|
|
|
|
sizeof(struct theme_descriptor));
|
|
|
|
if (!current) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("calloc failed");
|
2006-01-06 18:36:09 +03:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
free(filename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!ro_gui_theme_read_file_header(current, &file_header)) {
|
|
|
|
free(filename);
|
|
|
|
free(current);
|
|
|
|
return false;
|
2004-08-31 01:03:48 +04:00
|
|
|
}
|
2006-01-06 18:36:09 +03:00
|
|
|
current->filename = filename;
|
|
|
|
current->leafname = current->filename + strlen(folder) + 1;
|
|
|
|
|
2006-01-25 03:21:26 +03:00
|
|
|
/* don't add duplicates */
|
|
|
|
for (test = theme_descriptors; test; test = test->next) {
|
|
|
|
if (!strcmp(current->name, test->name)) {
|
|
|
|
free(current->filename);
|
|
|
|
free(current);
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-07 16:12:58 +03:00
|
|
|
}
|
|
|
|
|
2006-01-06 18:36:09 +03:00
|
|
|
/* link in our new descriptor at the head*/
|
|
|
|
if (theme_descriptors) {
|
|
|
|
current->next = theme_descriptors;
|
|
|
|
theme_descriptors->previous = current;
|
|
|
|
}
|
|
|
|
theme_descriptors = current;
|
|
|
|
return true;
|
2006-01-07 16:12:58 +03:00
|
|
|
|
2005-01-23 19:09:05 +03:00
|
|
|
}
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2005-01-23 19:09:05 +03:00
|
|
|
/**
|
|
|
|
* Fills in the basic details for a descriptor from a file header.
|
|
|
|
* The filename string is not set.
|
|
|
|
*
|
|
|
|
* \param descriptor the descriptor to set up
|
|
|
|
* \param file_header the header to read from
|
|
|
|
* \return false for a badly formed theme, true otherwise
|
|
|
|
*/
|
|
|
|
bool ro_gui_theme_read_file_header(struct theme_descriptor *descriptor,
|
2008-07-27 02:29:15 +04:00
|
|
|
struct theme_file_header *file_header)
|
|
|
|
{
|
2005-01-23 19:09:05 +03:00
|
|
|
if ((file_header->magic_value != 0x4d54534e) ||
|
|
|
|
(file_header->parser_version > 2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
strcpy(descriptor->name, file_header->name);
|
|
|
|
strcpy(descriptor->author, file_header->author);
|
|
|
|
descriptor->browser_background = file_header->browser_bg;
|
|
|
|
descriptor->hotlist_background = file_header->hotlist_bg;
|
|
|
|
descriptor->status_background = file_header->status_bg;
|
|
|
|
descriptor->status_foreground = file_header->status_fg;
|
|
|
|
descriptor->decompressed_size = file_header->decompressed_sprite_size;
|
|
|
|
descriptor->compressed_size = file_header->compressed_sprite_size;
|
|
|
|
if (file_header->parser_version >= 2) {
|
2005-04-10 02:37:09 +04:00
|
|
|
descriptor->throbber_right =
|
|
|
|
!(file_header->theme_flags & (1 << 0));
|
|
|
|
descriptor->throbber_redraw =
|
|
|
|
file_header->theme_flags & (1 << 1);
|
2005-01-23 19:09:05 +03:00
|
|
|
} else {
|
2005-04-10 02:37:09 +04:00
|
|
|
descriptor->throbber_right =
|
|
|
|
(file_header->theme_flags == 0x00);
|
|
|
|
descriptor->throbber_redraw = true;
|
2004-08-09 00:16:17 +04:00
|
|
|
}
|
2005-01-23 19:09:05 +03:00
|
|
|
return true;
|
2004-08-31 01:03:48 +04:00
|
|
|
}
|
2004-08-09 11:07:20 +04:00
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a theme ready for use.
|
|
|
|
*
|
|
|
|
* \param descriptor the theme_descriptor to open
|
|
|
|
* \param list whether to open all themes in the list
|
|
|
|
* \return whether the operation was successful
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
bool ro_gui_theme_open(struct theme_descriptor *descriptor, bool list)
|
|
|
|
{
|
2004-09-08 03:05:34 +04:00
|
|
|
fileswitch_object_type obj_type;
|
|
|
|
squash_output_status status;
|
2004-08-31 01:03:48 +04:00
|
|
|
os_coord dimensions;
|
|
|
|
os_mode mode;
|
2004-09-08 03:05:34 +04:00
|
|
|
os_error *error;
|
2005-04-10 02:37:09 +04:00
|
|
|
struct theme_descriptor *next_descriptor;
|
2005-01-23 19:09:05 +03:00
|
|
|
char sprite_name[16];
|
2009-03-28 03:56:29 +03:00
|
|
|
const char *name = sprite_name;
|
2004-08-31 01:03:48 +04:00
|
|
|
bool result = true;
|
|
|
|
int i, n;
|
2004-09-08 03:05:34 +04:00
|
|
|
int workspace_size, file_size;
|
|
|
|
char *raw_data, *workspace;
|
|
|
|
osspriteop_area *decompressed;
|
2005-04-10 02:37:09 +04:00
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
/* If we are freeing the whole of the list then we need to
|
|
|
|
start at the first descriptor.
|
2004-08-09 00:16:17 +04:00
|
|
|
*/
|
2005-04-10 02:37:09 +04:00
|
|
|
if (list && descriptor)
|
2004-08-31 01:03:48 +04:00
|
|
|
while (descriptor->previous) descriptor = descriptor->previous;
|
2003-11-20 03:16:31 +03:00
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
/* Open the themes
|
|
|
|
*/
|
2005-04-10 02:37:09 +04:00
|
|
|
for (; descriptor; descriptor = next_descriptor) {
|
|
|
|
/* see if we should iterate through the entire list */
|
|
|
|
if (list)
|
|
|
|
next_descriptor = descriptor->next;
|
|
|
|
else
|
|
|
|
next_descriptor = NULL;
|
|
|
|
|
|
|
|
/* if we are already loaded, increase the usage count */
|
2004-08-31 01:03:48 +04:00
|
|
|
if (descriptor->theme) {
|
|
|
|
descriptor->theme->users = descriptor->theme->users + 1;
|
2005-04-10 02:37:09 +04:00
|
|
|
continue;
|
|
|
|
}
|
2004-08-31 01:03:48 +04:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* create a new theme */
|
|
|
|
descriptor->theme = (struct theme *)calloc(1,
|
|
|
|
sizeof(struct theme));
|
|
|
|
if (!descriptor->theme) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("calloc() failed");
|
2005-04-10 02:37:09 +04:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
descriptor->theme->users = 1;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* try to load the associated file */
|
|
|
|
error = xosfile_read_stamped_no_path(descriptor->filename,
|
|
|
|
&obj_type, 0, 0, &file_size, 0, 0);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosfile_read_stamped_no_path: 0x%x: %s", error->errnum, error->errmess);
|
2005-04-10 02:37:09 +04:00
|
|
|
warn_user("FileError", error->errmess);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (obj_type != fileswitch_IS_FILE)
|
|
|
|
continue;
|
|
|
|
raw_data = malloc(file_size);
|
|
|
|
if (!raw_data) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("malloc() failed");
|
2005-04-10 02:37:09 +04:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
error = xosfile_load_stamped_no_path(descriptor->filename,
|
|
|
|
(byte *)raw_data, 0, 0, 0, 0, 0);
|
|
|
|
if (error) {
|
|
|
|
free(raw_data);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosfile_load_stamped_no_path: 0x%x: %s", error->errnum, error->errmess);
|
2005-04-10 02:37:09 +04:00
|
|
|
warn_user("FileError", error->errmess);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* decompress the new data */
|
|
|
|
error = xsquash_decompress_return_sizes(-1, &workspace_size, 0);
|
|
|
|
if (error) {
|
|
|
|
free(raw_data);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xsquash_decompress_return_sizes: 0x%x: %s", error->errnum, error->errmess);
|
2005-04-10 02:37:09 +04:00
|
|
|
warn_user("MiscError", error->errmess);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
decompressed = (osspriteop_area *)malloc(
|
|
|
|
descriptor->decompressed_size);
|
|
|
|
workspace = malloc(workspace_size);
|
|
|
|
if ((!decompressed) || (!workspace)) {
|
|
|
|
free(decompressed);
|
|
|
|
free(raw_data);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("malloc() failed");
|
2005-04-10 02:37:09 +04:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
error = xsquash_decompress(squash_INPUT_ALL_PRESENT, workspace,
|
|
|
|
(byte *)(raw_data + sizeof(
|
|
|
|
struct theme_file_header)),
|
|
|
|
descriptor->compressed_size,
|
|
|
|
(byte *)decompressed,
|
|
|
|
descriptor->decompressed_size,
|
|
|
|
&status, 0, 0, 0, 0);
|
|
|
|
free(workspace);
|
|
|
|
free(raw_data);
|
|
|
|
if (error) {
|
|
|
|
free(decompressed);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xsquash_decompress: 0x%x: %s", error->errnum, error->errmess);
|
2005-04-10 02:37:09 +04:00
|
|
|
warn_user("MiscError", error->errmess);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (status != 0) {
|
|
|
|
free(decompressed);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
descriptor->theme->sprite_area = decompressed;
|
|
|
|
|
|
|
|
/* find the highest sprite called 'throbber%i', and get the
|
|
|
|
* maximum dimensions for all 'thobber%i' icons. */
|
|
|
|
for (i = 1; i <= descriptor->theme->sprite_area->sprite_count;
|
|
|
|
i++) {
|
|
|
|
error = xosspriteop_return_name(osspriteop_USER_AREA,
|
|
|
|
descriptor->theme->sprite_area,
|
|
|
|
sprite_name, 16, i, 0);
|
2004-09-08 03:05:34 +04:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosspriteop_return_name: 0x%x: %s", error->errnum, error->errmess);
|
2004-09-08 03:05:34 +04:00
|
|
|
warn_user("MiscError", error->errmess);
|
2005-04-10 02:37:09 +04:00
|
|
|
continue;
|
2004-09-08 03:05:34 +04:00
|
|
|
}
|
2005-04-10 23:33:33 +04:00
|
|
|
if (strncmp(sprite_name, "throbber", 8))
|
2005-04-10 02:37:09 +04:00
|
|
|
continue;
|
2006-01-07 16:12:58 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* get the max sprite width/height */
|
|
|
|
error = xosspriteop_read_sprite_info(
|
|
|
|
osspriteop_USER_AREA,
|
|
|
|
descriptor->theme->sprite_area,
|
2009-03-28 03:56:29 +03:00
|
|
|
(osspriteop_id) name,
|
2005-04-10 02:37:09 +04:00
|
|
|
&dimensions.x, &dimensions.y,
|
2009-03-28 03:56:29 +03:00
|
|
|
(osbool *) 0, &mode);
|
2004-09-08 03:05:34 +04:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosspriteop_read_sprite_info: 0x%x: %s", error->errnum, error->errmess);
|
2004-09-08 03:05:34 +04:00
|
|
|
warn_user("MiscError", error->errmess);
|
2005-04-10 02:37:09 +04:00
|
|
|
continue;
|
2005-01-23 19:09:05 +03:00
|
|
|
}
|
2005-04-10 02:37:09 +04:00
|
|
|
ro_convert_pixels_to_os_units(&dimensions, mode);
|
|
|
|
if (descriptor->theme->throbber_width < dimensions.x)
|
|
|
|
descriptor->theme->throbber_width =
|
|
|
|
dimensions.x;
|
|
|
|
if (descriptor->theme->throbber_height < dimensions.y)
|
|
|
|
descriptor->theme->throbber_height =
|
|
|
|
dimensions.y;
|
|
|
|
|
|
|
|
/* get the throbber number */
|
|
|
|
n = atoi(sprite_name + 8);
|
|
|
|
if (descriptor->theme->throbber_frames < n)
|
|
|
|
descriptor->theme->throbber_frames = n;
|
2003-11-20 03:16:31 +03:00
|
|
|
}
|
|
|
|
}
|
2004-08-31 01:03:48 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies the theme to all current windows and subsequent ones.
|
|
|
|
*
|
|
|
|
* \param descriptor the theme_descriptor to open
|
|
|
|
* \return whether the operation was successful
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
bool ro_gui_theme_apply(struct theme_descriptor *descriptor)
|
|
|
|
{
|
2004-08-31 01:03:48 +04:00
|
|
|
struct theme_descriptor *theme_previous;
|
2004-08-09 11:07:20 +04:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* check if the theme is already applied */
|
|
|
|
if (descriptor == theme_current)
|
|
|
|
return true;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* re-open the new-theme and release the current theme */
|
|
|
|
if (!ro_gui_theme_open(descriptor, false))
|
2005-01-13 23:01:03 +03:00
|
|
|
return false;
|
2004-08-31 01:03:48 +04:00
|
|
|
theme_previous = theme_current;
|
|
|
|
theme_current = descriptor;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
/* apply the theme to all the current toolbar-ed windows */
|
|
|
|
ro_toolbar_theme_update();
|
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
ro_gui_theme_close(theme_previous, false);
|
|
|
|
return true;
|
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-08-31 01:03:48 +04:00
|
|
|
* Closes a theme after use.
|
2003-11-20 03:16:31 +03:00
|
|
|
*
|
2004-08-31 01:03:48 +04:00
|
|
|
* \param descriptor the theme_descriptor to close
|
|
|
|
* \param list whether to open all themes in the list
|
|
|
|
* \return whether the operation was successful
|
2003-11-20 03:16:31 +03:00
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_theme_close(struct theme_descriptor *descriptor, bool list)
|
|
|
|
{
|
2002-10-15 14:47:44 +04:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
if (!descriptor)
|
|
|
|
return;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* move to the start of the list */
|
|
|
|
while (list && descriptor->previous)
|
|
|
|
descriptor = descriptor->previous;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* close the themes */
|
2004-08-31 01:03:48 +04:00
|
|
|
while (descriptor) {
|
|
|
|
if (descriptor->theme) {
|
|
|
|
descriptor->theme->users = descriptor->theme->users - 1;
|
|
|
|
if (descriptor->theme->users <= 0) {
|
|
|
|
free(descriptor->theme->sprite_area);
|
|
|
|
free(descriptor->theme);
|
|
|
|
descriptor->theme = NULL;
|
|
|
|
}
|
|
|
|
}
|
2005-04-10 02:37:09 +04:00
|
|
|
if (!list)
|
2004-08-31 01:03:48 +04:00
|
|
|
return;
|
2005-04-10 02:37:09 +04:00
|
|
|
descriptor = descriptor->next;
|
2004-05-05 02:23:44 +04:00
|
|
|
}
|
2004-08-31 01:03:48 +04:00
|
|
|
}
|
|
|
|
|
2004-05-05 02:23:44 +04:00
|
|
|
|
2004-08-31 01:03:48 +04:00
|
|
|
/**
|
|
|
|
* Frees any unused theme descriptors.
|
|
|
|
*
|
|
|
|
* \param descriptor the theme_descriptor to free
|
|
|
|
*/
|
2008-07-27 02:29:15 +04:00
|
|
|
void ro_gui_theme_free(struct theme_descriptor *descriptor)
|
|
|
|
{
|
2004-08-31 01:03:48 +04:00
|
|
|
struct theme_descriptor *next_descriptor;
|
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
if (!descriptor)
|
|
|
|
return;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* move to the start of the list */
|
|
|
|
while (descriptor->previous)
|
2005-01-23 19:09:05 +03:00
|
|
|
descriptor = descriptor->previous;
|
2004-05-05 02:23:44 +04:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* free closed themes */
|
|
|
|
for (; descriptor; descriptor = next_descriptor) {
|
2004-08-31 01:03:48 +04:00
|
|
|
next_descriptor = descriptor->next;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* no theme? no descriptor */
|
2004-08-31 01:03:48 +04:00
|
|
|
if (!descriptor->theme) {
|
|
|
|
if (descriptor->previous)
|
2005-04-10 02:37:09 +04:00
|
|
|
descriptor->previous->next = descriptor->next;
|
2004-08-31 01:03:48 +04:00
|
|
|
if (descriptor->next)
|
2005-04-10 02:37:09 +04:00
|
|
|
descriptor->next->previous =
|
|
|
|
descriptor->previous;
|
2005-01-13 23:01:03 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* keep the cached list in sync */
|
2004-08-31 01:03:48 +04:00
|
|
|
if (theme_descriptors == descriptor)
|
2005-04-10 02:37:09 +04:00
|
|
|
theme_descriptors = next_descriptor;
|
2005-01-23 19:09:05 +03:00
|
|
|
|
2005-04-10 02:37:09 +04:00
|
|
|
/* release any memory */
|
2004-08-31 01:03:48 +04:00
|
|
|
free(descriptor->filename);
|
|
|
|
free(descriptor);
|
|
|
|
}
|
|
|
|
}
|
2004-07-08 02:09:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|