NetSurf
Functions | Variables
theme.c File Reference

Window themes implementation. More...

#include <alloca.h>
#include <assert.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "oslib/dragasprite.h"
#include "oslib/os.h"
#include "oslib/osgbpb.h"
#include "oslib/osfile.h"
#include "oslib/osfind.h"
#include "oslib/osspriteop.h"
#include "oslib/wimpspriteop.h"
#include "oslib/squash.h"
#include "oslib/wimp.h"
#include "oslib/wimpextend.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "riscos/cookies.h"
#include "riscos/dialog.h"
#include "riscos/global_history.h"
#include "riscos/gui.h"
#include "riscos/hotlist.h"
#include "riscos/menus.h"
#include "riscos/theme.h"
#include "riscos/toolbar.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/wimputils.h"
Include dependency graph for theme.c:

Go to the source code of this file.

Functions

static bool ro_gui_theme_add_descriptor (const char *folder, const char *leafname)
 Checks a theme is valid and adds it to the current list. More...
 
static void ro_gui_theme_get_available_in_dir (const char *directory)
 Adds the themes in a directory to the global cache. More...
 
static void ro_gui_theme_free (struct theme_descriptor *descriptor)
 Frees any unused theme descriptors. More...
 
void ro_gui_theme_initialise (void)
 Initialise the theme handler. More...
 
void ro_gui_theme_finalise (void)
 Finalise the theme handler. More...
 
struct theme_descriptorro_gui_theme_find (const char *leafname)
 Finds a theme from the cached values. More...
 
struct theme_descriptorro_gui_theme_get_available (void)
 Reads and caches the currently available themes. More...
 
struct theme_descriptorro_gui_theme_get_current (void)
 Returns the current theme handle, or NULL if none is set. More...
 
osspriteop_area * ro_gui_theme_get_sprites (struct theme_descriptor *descriptor)
 Returns a sprite area for use with the given theme. More...
 
int ro_gui_theme_get_style_element (struct theme_descriptor *descriptor, theme_style style, theme_element element)
 Returns an interger element from the specified theme, or the current theme if the descriptor is NULL. More...
 
bool ro_gui_theme_get_throbber_data (struct theme_descriptor *descriptor, int *frames, int *width, int *height, bool *right, bool *redraw)
 Returns details of the throbber as defined in a theme. More...
 
bool ro_gui_theme_read_file_header (struct theme_descriptor *descriptor, struct theme_file_header *file_header)
 Fills in the basic details for a descriptor from a file header. More...
 
bool ro_gui_theme_open (struct theme_descriptor *descriptor, bool list)
 Opens a theme ready for use. More...
 
bool ro_gui_theme_apply (struct theme_descriptor *descriptor)
 Applies the theme to all current windows and subsequent ones. More...
 
void ro_gui_theme_close (struct theme_descriptor *descriptor, bool list)
 Closes a theme after use. More...
 

Variables

static struct theme_descriptortheme_current = NULL
 
static struct theme_descriptortheme_descriptors = NULL
 

Detailed Description

Window themes implementation.

Definition in file theme.c.

Function Documentation

◆ ro_gui_theme_add_descriptor()

bool ro_gui_theme_add_descriptor ( const char *  folder,
const char *  leafname 
)
static

Checks a theme is valid and adds it to the current list.

Parameters
folderthe theme folder
leafnamethe theme leafname
Returns
whether the theme was added

Definition at line 357 of file theme.c.

References theme_descriptor::filename, theme_descriptor::leafname, theme_descriptor::name, theme_descriptor::next, NSLOG, theme_descriptor::previous, ro_gui_theme_read_file_header(), ro_warn_user(), and theme_descriptors.

Referenced by ro_gui_theme_get_available(), and ro_gui_theme_get_available_in_dir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_theme_apply()

bool ro_gui_theme_apply ( struct theme_descriptor descriptor)

Applies the theme to all current windows and subsequent ones.

Parameters
descriptorthe theme_descriptor to open
Returns
whether the operation was successful

Definition at line 666 of file theme.c.

References ro_gui_theme_close(), ro_gui_theme_open(), ro_toolbar_theme_update(), and theme_current.

Referenced by ro_gui_options_theme_ok(), ro_gui_theme_initialise(), and ro_gui_theme_install_apply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_theme_close()

void ro_gui_theme_close ( struct theme_descriptor descriptor,
bool  list 
)

Closes a theme after use.

Parameters
descriptorthe theme_descriptor to close
listwhether to open all themes in the list
Returns
whether the operation was successful

Definition at line 695 of file theme.c.

References theme_descriptor::next, theme_descriptor::previous, theme::sprite_area, theme_descriptor::theme, and theme::users.

Referenced by ro_gui_options_theme_free(), ro_gui_theme_apply(), and ro_gui_theme_finalise().

Here is the caller graph for this function:

◆ ro_gui_theme_finalise()

void ro_gui_theme_finalise ( void  )

Finalise the theme handler.

Definition at line 83 of file theme.c.

References ro_gui_theme_close(), ro_gui_theme_free(), theme_current, and theme_descriptors.

Here is the call graph for this function:

◆ ro_gui_theme_find()

struct theme_descriptor * ro_gui_theme_find ( const char *  leafname)

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().

Parameters
leafnamethe filename of the theme_descriptor to return
Returns
the requested theme_descriptor, or NULL if not found

Definition at line 100 of file theme.c.

References theme_descriptor::leafname, theme_descriptor::next, and theme_descriptors.

Referenced by ro_gui_options_theme_click(), ro_gui_options_theme_initialise(), ro_gui_theme_initialise(), and ro_gui_theme_install_apply().

Here is the caller graph for this function:

◆ ro_gui_theme_free()

void ro_gui_theme_free ( struct theme_descriptor descriptor)
static

Frees any unused theme descriptors.

Parameters
descriptorthe theme_descriptor to free

Definition at line 727 of file theme.c.

References theme_descriptor::filename, theme_descriptor::next, theme_descriptor::previous, theme_descriptor::theme, and theme_descriptors.

Referenced by ro_gui_theme_finalise(), and ro_gui_theme_get_available().

Here is the caller graph for this function:

◆ ro_gui_theme_get_available()

struct theme_descriptor * ro_gui_theme_get_available ( void  )

Reads and caches the currently available themes.

Returns
the requested theme_descriptor, or NULL if not found

Definition at line 125 of file theme.c.

References theme_descriptor::name, theme_descriptor::next, nsoption_charp, theme_descriptor::previous, ro_gui_theme_add_descriptor(), ro_gui_theme_free(), ro_gui_theme_get_available_in_dir(), and theme_descriptors.

Referenced by ro_gui_options_theme_load(), ro_gui_theme_initialise(), and ro_gui_theme_install_apply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_theme_get_available_in_dir()

static void ro_gui_theme_get_available_in_dir ( const char *  directory)
static

Adds the themes in a directory to the global cache.

Parameters
directorythe directory to scan

Definition at line 172 of file theme.c.

References NSLOG, ro_gui_theme_add_descriptor(), and ro_warn_user().

Referenced by ro_gui_theme_get_available().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_theme_get_current()

struct theme_descriptor * ro_gui_theme_get_current ( void  )

Returns the current theme handle, or NULL if none is set.

Returns
The theme descriptor handle, or NULL.

Definition at line 207 of file theme.c.

References theme_current.

◆ ro_gui_theme_get_sprites()

osspriteop_area * ro_gui_theme_get_sprites ( struct theme_descriptor descriptor)

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.

Parameters
*descriptorThe theme to use, or NULL for the current.
Returns
A pointer to the theme sprite area.

Definition at line 221 of file theme.c.

References theme::sprite_area, theme_descriptor::theme, and theme_current.

Referenced by ro_gui_button_bar_create(), ro_gui_button_bar_rebuild(), ro_gui_throbber_create(), ro_gui_throbber_rebuild(), ro_gui_url_bar_create(), and ro_toolbar_rebuild().

Here is the caller graph for this function:

◆ ro_gui_theme_get_style_element()

int ro_gui_theme_get_style_element ( struct theme_descriptor descriptor,
theme_style  style,
theme_element  element 
)

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.

Parameters
*descriptorThe theme to use, or NULL for the current.
styleThe style to use.
elementThe style element to return.
Returns
The requested value, or 0.

Definition at line 251 of file theme.c.

References theme_descriptor::browser_background, theme_descriptor::hotlist_background, theme_descriptor::status_background, theme_descriptor::status_foreground, theme_current, THEME_ELEMENT_BACKGROUND, THEME_ELEMENT_FOREGROUND, THEME_STYLE_BROWSER_TOOLBAR, THEME_STYLE_COOKIES_TOOLBAR, THEME_STYLE_GLOBAL_HISTORY_TOOLBAR, THEME_STYLE_HOTLIST_TOOLBAR, THEME_STYLE_NONE, and THEME_STYLE_STATUS_BAR.

Referenced by ro_gui_button_bar_rebuild(), and ro_toolbar_rebuild().

Here is the caller graph for this function:

◆ ro_gui_theme_get_throbber_data()

bool ro_gui_theme_get_throbber_data ( struct theme_descriptor descriptor,
int *  frames,
int *  width,
int *  height,
bool *  right,
bool *  redraw 
)

Returns details of the throbber as defined in a theme.

Parameters
*descriptorThe theme of interest (NULL for current).
*framesReturn the number of animation frames.
*widthReturn the throbber width.
*heightReturn the throbber height.
*rightReturn the 'locate on right' flag.
*redrawReturn the 'forcible redraw' flag.
Returns
true if meaningful data has been returned; else false.

Definition at line 325 of file theme.c.

References height, theme_descriptor::theme, theme_current, theme::throbber_frames, theme::throbber_height, theme_descriptor::throbber_redraw, theme_descriptor::throbber_right, theme::throbber_width, and width.

Referenced by ro_gui_throbber_create(), ro_gui_throbber_rebuild(), and ro_toolbar_rebuild().

Here is the caller graph for this function:

◆ ro_gui_theme_initialise()

void ro_gui_theme_initialise ( void  )

Initialise the theme handler.

Definition at line 68 of file theme.c.

References nsoption_charp, ro_gui_theme_apply(), ro_gui_theme_find(), ro_gui_theme_get_available(), and theme_descriptors.

Referenced by gui_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_theme_open()

bool ro_gui_theme_open ( struct theme_descriptor descriptor,
bool  list 
)

Opens a theme ready for use.

Parameters
descriptorthe theme_descriptor to open
listwhether to open all themes in the list
Returns
whether the operation was successful

Definition at line 488 of file theme.c.

References theme_descriptor::compressed_size, theme_descriptor::decompressed_size, theme_descriptor::filename, mode, theme_descriptor::name, theme_descriptor::next, NSLOG, theme_descriptor::previous, result, ro_convert_pixels_to_os_units(), ro_warn_user(), theme::sprite_area, theme_descriptor::theme, theme::throbber_frames, theme::throbber_height, theme::throbber_width, and theme::users.

Referenced by ro_gui_options_theme_load(), and ro_gui_theme_apply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_theme_read_file_header()

bool ro_gui_theme_read_file_header ( struct theme_descriptor descriptor,
struct theme_file_header file_header 
)

Fills in the basic details for a descriptor from a file header.

The filename string is not set.

Parameters
descriptorthe descriptor to set up
file_headerthe header to read from
Returns
false for a badly formed theme, true otherwise

Definition at line 452 of file theme.c.

References theme_file_header::author, theme_descriptor::author, theme_descriptor::browser_background, theme_file_header::browser_bg, theme_descriptor::compressed_size, theme_file_header::compressed_sprite_size, theme_descriptor::decompressed_size, theme_file_header::decompressed_sprite_size, theme_descriptor::hotlist_background, theme_file_header::hotlist_bg, theme_file_header::magic_value, theme_file_header::name, theme_descriptor::name, theme_file_header::parser_version, theme_descriptor::status_background, theme_file_header::status_bg, theme_file_header::status_fg, theme_descriptor::status_foreground, theme_file_header::theme_flags, theme_descriptor::throbber_redraw, and theme_descriptor::throbber_right.

Referenced by ro_gui_theme_add_descriptor(), and theme_install_read().

Here is the caller graph for this function:

Variable Documentation

◆ theme_current

struct theme_descriptor* theme_current = NULL
static
Todo:
provide a proper interface for these and make them static again!

Definition at line 58 of file theme.c.

Referenced by ro_gui_theme_apply(), ro_gui_theme_finalise(), ro_gui_theme_get_current(), ro_gui_theme_get_sprites(), ro_gui_theme_get_style_element(), and ro_gui_theme_get_throbber_data().

◆ theme_descriptors

struct theme_descriptor* theme_descriptors = NULL
static