r3002 rjw - in /trunk/netsurf/utils: hashtable.c hashtable.h
by netsurf@semichrome.net
Author: rjw
Date: Fri Oct 13 16:09:30 2006
New Revision: 3002
URL: http://svn.semichrome.net?rev=3002&view=rev
Log:
Optimise and tidy up code.
Modified:
trunk/netsurf/utils/hashtable.c
trunk/netsurf/utils/hashtable.h
Modified: trunk/netsurf/utils/hashtable.c
URL: http://svn.semichrome.net/trunk/netsurf/utils/hashtable.c?rev=3002&r1=300...
==============================================================================
--- trunk/netsurf/utils/hashtable.c (original)
+++ trunk/netsurf/utils/hashtable.c Fri Oct 13 16:09:30 2006
@@ -3,6 +3,7 @@
* Licensed under the GNU General Public License,
* http://www.opensource.org/licenses/gpl-license
* Copyright 2006 Rob Kendrick <rjek(a)rjek.com>
+ * Copyright 2006 Richard Wilson <info(a)tinct.net>
*/
/** \file
@@ -18,9 +19,23 @@
#include "netsurf/utils/hashtable.h"
#include "netsurf/utils/log.h"
+
+struct hash_entry {
+ char *key;
+ char *value;
+ unsigned int key_length;
+ struct hash_entry *next;
+};
+
+struct hash_table {
+ unsigned int nchains;
+ struct hash_entry **chain;
+};
+
+
/**
* Create a new hash table, and return a context for it. The memory consumption
- * of a hash table is approximately 8 + (nchains * 12) bytes if it is empty.
+ * of a hash table is approximately 8 + (nchains * 16) bytes if it is empty.
*
* \param chains Number of chains/buckets this hash table will have. This
* should be a prime number, and ideally a prime number just
@@ -126,6 +141,7 @@
return false;
}
+ e->key_length = strlen(key);
e->next = ht->chain[c];
ht->chain[c] = e;
@@ -144,6 +160,7 @@
{
unsigned int h;
unsigned int c;
+ unsigned int key_length;
struct hash_entry *e;
if (ht == NULL || key == NULL)
@@ -151,13 +168,11 @@
h = hash_string_fnv(key);
c = h % ht->nchains;
- e = ht->chain[c];
-
- while (e) {
- if (!strcmp(key, e->key))
+ key_length = strlen(key);
+
+ for (e = ht->chain[c]; e; e = e->next)
+ if ((key_length == e->key_length) && (!strcmp(key, e->key)))
return e->value;
- e = e->next;
- }
return NULL;
@@ -174,15 +189,14 @@
unsigned int hash_string_fnv(const char *datum)
{
- unsigned int z = 0x01000193, i = 0;
+ unsigned int z = 0x01000193;
if (datum == NULL)
return 0;
- while (datum[i]) {
+ while (*datum) {
z *= 0x01000193;
- z ^= datum[i];
- datum++;
+ z ^= *datum++;
}
return z;
Modified: trunk/netsurf/utils/hashtable.h
URL: http://svn.semichrome.net/trunk/netsurf/utils/hashtable.h?rev=3002&r1=300...
==============================================================================
--- trunk/netsurf/utils/hashtable.h (original)
+++ trunk/netsurf/utils/hashtable.h Fri Oct 13 16:09:30 2006
@@ -13,16 +13,7 @@
#include <stdbool.h>
-struct hash_entry {
- char *key;
- char *value;
- struct hash_entry *next;
-};
-
-struct hash_table {
- unsigned int nchains;
- struct hash_entry **chain;
-};
+struct hash_table;
struct hash_table *hash_create(unsigned int chains);
void hash_destroy(struct hash_table *ht);
16 years, 3 months
r3001 rjw - /trunk/netsurf/riscos/textarea.c
by netsurf@semichrome.net
Author: rjw
Date: Thu Oct 12 16:53:57 2006
New Revision: 3001
URL: http://svn.semichrome.net?rev=3001&view=rev
Log:
Remove the need for a text area list.
Modified:
trunk/netsurf/riscos/textarea.c
Modified: trunk/netsurf/riscos/textarea.c
URL: http://svn.semichrome.net/trunk/netsurf/riscos/textarea.c?rev=3001&r1=300...
==============================================================================
--- trunk/netsurf/riscos/textarea.c (original)
+++ trunk/netsurf/riscos/textarea.c Thu Oct 12 16:53:57 2006
@@ -39,7 +39,7 @@
unsigned int b_length; /**< Byte length of line */
};
-static struct text_area {
+struct text_area {
#define MAGIC (('T'<<24) | ('E'<<16) | ('X'<<8) | 'T')
unsigned int magic; /**< Magic word, for sanity */
@@ -73,7 +73,7 @@
struct text_area *next; /**< Next text area in list */
struct text_area *prev; /**< Prev text area in list */
-} *text_areas;
+};
static wimp_window text_area_definition = {
{0, 0, 16, 16},
@@ -100,7 +100,6 @@
{}
};
-static struct text_area *textarea_from_w(wimp_w self);
static void textarea_reflow(struct text_area *ta, unsigned int line);
static bool textarea_mouse_click(wimp_pointer *pointer);
static bool textarea_key_press(wimp_key *key);
@@ -259,17 +258,11 @@
return 0;
}
- /* Insert into list */
- ret->prev = NULL;
- ret->next = text_areas;
- if (text_areas)
- text_areas->prev = ret;
- text_areas = ret;
-
/* make available for immediate use */
textarea_reflow(ret, 0);
/* and register our event handlers */
+ ro_gui_wimp_event_set_user_data(ret->window, ret);
ro_gui_wimp_event_register_mouse_click(ret->window,
textarea_mouse_click);
ro_gui_wimp_event_register_keypress(ret->window,
@@ -303,16 +296,6 @@
}
ro_gui_wimp_event_finalise(ta->window);
-
- /* Remove from list */
- if (ta->next)
- ta->next->prev = ta->prev;
-
- if (ta->prev)
- ta->prev->next = ta->next;
- else
- text_areas = ta->next;
-
free(ta->font_family);
free(ta->text);
@@ -691,23 +674,6 @@
}
/** \todo Selection handling */
-
-/**
- * Find a text area in the list
- *
- * \param self Text area to find
- * \return Pointer to text area, or NULL if not found
- */
-struct text_area *textarea_from_w(wimp_w self)
-{
- struct text_area *ta;
-
- for (ta = text_areas; ta; ta = ta->next)
- if (ta->window == self)
- return ta;
-
- return NULL;
-}
/**
* Reflow a text area from the given line onwards
@@ -905,9 +871,7 @@
{
struct text_area *ta;
- ta = textarea_from_w(pointer->w);
- if (!ta)
- return false;
+ ta = (struct text_area *)ro_gui_wimp_event_get_user_data(pointer->w);
textarea_set_caret_xy((uintptr_t)ta, pointer->pos.x, pointer->pos.y);
return true;
@@ -930,9 +894,7 @@
unsigned int c_pos;
os_error *error;
- ta = textarea_from_w(key->w);
- if (!ta)
- return false;
+ ta = (struct text_area *)ro_gui_wimp_event_get_user_data(key->w);
if (ta->flags & TEXTAREA_READONLY)
return true;
@@ -1087,9 +1049,7 @@
rufl_code code;
os_error *error;
- ta = textarea_from_w(redraw->w);
- if (!ta)
- return;
+ ta = (struct text_area *)ro_gui_wimp_event_get_user_data(redraw->w);
if (update)
error = xwimp_update_window(redraw, &more);
@@ -1192,12 +1152,7 @@
*/
void textarea_open(wimp_open *open)
{
- struct text_area *ta;
os_error *error;
-
- ta = textarea_from_w(open->w);
- if (!ta)
- return;
error = xwimp_open_window(open);
if (error) {
16 years, 3 months
r2999 jmb - /trunk/netsurf/utils/filename.c
by netsurf@semichrome.net
Author: jmb
Date: Thu Oct 12 15:01:14 2006
New Revision: 2999
URL: http://svn.semichrome.net?rev=2999&view=rev
Log:
Fix bad pointer increment
Modified:
trunk/netsurf/utils/filename.c
Modified: trunk/netsurf/utils/filename.c
URL: http://svn.semichrome.net/trunk/netsurf/utils/filename.c?rev=2999&r1=2998...
==============================================================================
--- trunk/netsurf/utils/filename.c (original)
+++ trunk/netsurf/utils/filename.c Thu Oct 12 15:01:14 2006
@@ -152,7 +152,7 @@
if (!directory)
return false;
- for (start = directory; *start != '\0'; *start++) {
+ for (start = directory; *start != '\0'; start++) {
if (*start == '/') {
*start = '\0';
mkdir(directory, S_IRWXU);
@@ -434,7 +434,7 @@
char *filename_as_url(const char *filename) {
char *temp, *url;
int length;
-
+
length = strlen(TEMP_FILENAME_PREFIX) + strlen(filename) + 2;
temp = malloc(length);
if (!temp) {
16 years, 3 months
r2998 jmb - in /trunk/netsurf: riscos/gui.c utils/hashtable.c utils/messages.c
by netsurf@semichrome.net
Author: jmb
Date: Thu Oct 12 15:00:40 2006
New Revision: 2998
URL: http://svn.semichrome.net?rev=2998&view=rev
Log:
Fix attempts to call die() before messages_hash exists:
1) Make hash_* more robust in the face of bad parameters
2) Make messages_* more robust in the face of bad parameters
3) Tidy up gui_init such that localised messages are loaded at the
earliest opportunity
Modified:
trunk/netsurf/riscos/gui.c
trunk/netsurf/utils/hashtable.c
trunk/netsurf/utils/messages.c
Modified: trunk/netsurf/riscos/gui.c
URL: http://svn.semichrome.net/trunk/netsurf/riscos/gui.c?rev=2998&r1=2997&r2=...
==============================================================================
--- trunk/netsurf/riscos/gui.c (original)
+++ trunk/netsurf/riscos/gui.c Thu Oct 12 15:00:40 2006
@@ -299,33 +299,24 @@
while (*help == 9) help++;
if (!memcmp(help, "0.55", 4))
#endif
- ro_plot_patterned_lines = false;
- }
-
- atexit(ro_gui_cleanup);
- prev_sigs.sigabrt = signal(SIGABRT, ro_gui_signal);
- prev_sigs.sigfpe = signal(SIGFPE, ro_gui_signal);
- prev_sigs.sigill = signal(SIGILL, ro_gui_signal);
- prev_sigs.sigint = signal(SIGINT, ro_gui_signal);
- prev_sigs.sigsegv = signal(SIGSEGV, ro_gui_signal);
- prev_sigs.sigterm = signal(SIGTERM, ro_gui_signal);
-
- if (prev_sigs.sigabrt == SIG_ERR || prev_sigs.sigfpe == SIG_ERR ||
- prev_sigs.sigill == SIG_ERR ||
- prev_sigs.sigint == SIG_ERR ||
- prev_sigs.sigsegv == SIG_ERR ||
- prev_sigs.sigterm == SIG_ERR)
- die("Failed registering signal handlers");
-
- filename_initialise();
-
-#ifdef WITH_SAVE_COMPLETE
- save_complete_init();
-#endif
-
+ ro_plot_patterned_lines = false;
+ }
+
+ /* Read in the options */
options_read("NetSurf:Choices");
- /* set defaults for absent strings */
+ /* Choose the interface language to use */
+ ro_gui_choose_language();
+
+ /* Load in our language-specific Messages */
+ if ((length = snprintf(path, sizeof(path),
+ "NetSurf:Resources.%s.Messages",
+ option_language)) < 0 || length >= (int)sizeof(path))
+ die("Failed to locate Messages resource.");
+ messages_load(path);
+ messages_load("NetSurf:Resources.LangNames");
+
+ /* Set defaults for absent option strings */
if (!option_theme)
option_theme = strdup("Aletheia");
if (!option_toolbar_browser)
@@ -369,18 +360,31 @@
!option_theme_save)
die("Failed initialising string options");
- /* create our choices directories */
+ /* Create our choices directories */
ro_gui_create_dirs();
+ /* Register exit and signal handlers */
+ atexit(ro_gui_cleanup);
+ prev_sigs.sigabrt = signal(SIGABRT, ro_gui_signal);
+ prev_sigs.sigfpe = signal(SIGFPE, ro_gui_signal);
+ prev_sigs.sigill = signal(SIGILL, ro_gui_signal);
+ prev_sigs.sigint = signal(SIGINT, ro_gui_signal);
+ prev_sigs.sigsegv = signal(SIGSEGV, ro_gui_signal);
+ prev_sigs.sigterm = signal(SIGTERM, ro_gui_signal);
+
+ if (prev_sigs.sigabrt == SIG_ERR || prev_sigs.sigfpe == SIG_ERR ||
+ prev_sigs.sigill == SIG_ERR ||
+ prev_sigs.sigint == SIG_ERR ||
+ prev_sigs.sigsegv == SIG_ERR ||
+ prev_sigs.sigterm == SIG_ERR)
+ die("Failed registering signal handlers");
+
+ /* Load in UI sprites */
gui_sprites = ro_gui_load_sprite_file("NetSurf:Resources.Sprites");
if (!gui_sprites)
die("Unable to load Sprites.");
- ro_gui_choose_language();
-
- bitmap_initialise_memory();
- urldb_load(option_url_path);
- urldb_load_cookies(option_cookie_file);
-
+
+ /* Find NetSurf directory */
nsdir_temp = getenv("NetSurf$Dir");
if (!nsdir_temp)
die("Failed to locate NetSurf directory");
@@ -388,18 +392,28 @@
if (!NETSURF_DIR)
die("Failed duplicating NetSurf directory string");
- if ((length = snprintf(path, sizeof(path),
- "NetSurf:Resources.%s.Messages",
- option_language)) < 0 || length >= (int)sizeof(path))
- die("Failed to locate Messages resource.");
- messages_load(path);
- messages_load("NetSurf:Resources.LangNames");
-
+ /* Initialise stylesheet URLs */
default_stylesheet_url = strdup("file:///NetSurf:/Resources/CSS");
adblock_stylesheet_url = strdup("file:///NetSurf:/Resources/AdBlock");
if (!default_stylesheet_url || !adblock_stylesheet_url)
die("Failed initialising string constants.");
+ /* Initialise filename allocator */
+ filename_initialise();
+
+ /* Initialise save complete functionality */
+#ifdef WITH_SAVE_COMPLETE
+ save_complete_init();
+#endif
+
+ /* Initialise bitmap memory pool */
+ bitmap_initialise_memory();
+
+ /* Load in visited URLs and Cookies */
+ urldb_load(option_url_path);
+ urldb_load_cookies(option_cookie_file);
+
+ /* Initialise with the wimp */
error = xwimp_initialise(wimp_VERSION_RO38, task_name,
(const wimp_message_list *) &task_messages, 0,
&task_handle);
@@ -408,7 +422,7 @@
error->errnum, error->errmess));
die(error->errmess);
}
- /* register our message handlers */
+ /* Register message handlers */
ro_message_register_route(message_HELP_REQUEST,
ro_gui_interactive_help_request);
ro_message_register_route(message_DATA_OPEN,
@@ -427,9 +441,11 @@
ro_gui_selection_drag_claim);
ro_message_register_route(message_WINDOW_INFO,
ro_msg_window_info);
- /* end of handler registration */
-
+
+ /* Initialise the font subsystem */
nsfont_init();
+
+ /* Initialise global information */
ro_gui_get_screen_properties();
ro_gui_wimp_get_desktop_font();
@@ -437,8 +453,7 @@
if (getenv("NetSurf$Start_URI_Handler"))
xwimp_start_task("Desktop", 0);
- /* Open the templates
- */
+ /* Open the templates */
if ((length = snprintf(path, sizeof(path),
"NetSurf:Resources.%s.Templates",
option_language)) < 0 || length >= (int)sizeof(path))
@@ -449,17 +464,30 @@
error->errnum, error->errmess));
die(error->errmess);
}
- ro_gui_theme_initialise(); /* initialise themes before dialogs */
- ro_gui_dialog_init(); /* must be done after sprite loading */
+
+ /* Initialise themes before dialogs */
+ ro_gui_theme_initialise();
+ /* Initialise dialog windows (must be after UI sprites are loaded) */
+ ro_gui_dialog_init();
+ /* Initialise download window */
ro_gui_download_init();
+ /* Initialise menus */
ro_gui_menu_init();
+ /* Initialise query windows */
ro_gui_query_init();
+ /* Initialise the history subsystem */
ro_gui_history_init();
+
+ /* Done with the templates file */
wimp_close_template();
- ro_gui_tree_initialise(); /* must be done after sprite loading */
-
+ /* Initialise tree views (must be after UI sprites are loaded) */
+ ro_gui_tree_initialise();
+
+ /* Create Iconbar icon */
ro_gui_icon_bar_create();
+
+ /* Finally, check Inet$Resolvers for sanity */
ro_gui_check_resolvers();
}
@@ -2196,7 +2224,7 @@
* Should only be used during initialisation.
*/
-void die(const char *error)
+void die(const char * const error)
{
os_error warn_error;
Modified: trunk/netsurf/utils/hashtable.c
URL: http://svn.semichrome.net/trunk/netsurf/utils/hashtable.c?rev=2998&r1=299...
==============================================================================
--- trunk/netsurf/utils/hashtable.c (original)
+++ trunk/netsurf/utils/hashtable.c Thu Oct 12 15:00:40 2006
@@ -28,7 +28,7 @@
* \return struct hash_table containing the context of this hash table or NULL
* if there is insufficent memory to create it and its chains.
*/
-
+
struct hash_table *hash_create(unsigned int chains)
{
struct hash_table *r = malloc(sizeof(struct hash_table));
@@ -61,11 +61,14 @@
{
unsigned int i;
+ if (ht == NULL)
+ return;
+
for (i = 0; i < ht->nchains; i++) {
if (ht->chain[i] != NULL) {
struct hash_entry *e = ht->chain[i];
while (e) {
- struct hash_entry *n = e->next;
+ struct hash_entry *n = e->next;
free(e->key);
free(e->value);
free(e);
@@ -93,14 +96,20 @@
bool hash_add(struct hash_table *ht, const char *key, const char *value)
{
- unsigned int h = hash_string_fnv(key);
- unsigned int c = h % ht->nchains;
+ unsigned int h;
+ unsigned int c;
struct hash_entry *e = malloc(sizeof(struct hash_entry));
-
+
+ if (ht == NULL || key == NULL || value == NULL)
+ return false;
+
if (e == NULL) {
LOG(("Not enough memory for hash entry."));
return false;
}
+
+ h = hash_string_fnv(key);
+ c = h % ht->nchains;
e->key = strdup(key);
if (e->key == NULL) {
@@ -108,7 +117,7 @@
free(e);
return false;
}
-
+
e->value = strdup(value);
if (e->value == NULL) {
LOG(("Unable to strdup() value for hash table."));
@@ -133,10 +142,17 @@
const char *hash_get(struct hash_table *ht, const char *key)
{
- unsigned int h = hash_string_fnv(key);
- unsigned int c = h % ht->nchains;
- struct hash_entry *e = ht->chain[c];
-
+ unsigned int h;
+ unsigned int c;
+ struct hash_entry *e;
+
+ if (ht == NULL || key == NULL)
+ return NULL;
+
+ h = hash_string_fnv(key);
+ c = h % ht->nchains;
+ e = ht->chain[c];
+
while (e) {
if (!strcmp(key, e->key))
return e->value;
@@ -159,6 +175,9 @@
unsigned int hash_string_fnv(const char *datum)
{
unsigned int z = 0x01000193, i = 0;
+
+ if (datum == NULL)
+ return 0;
while (datum[i]) {
z *= 0x01000193;
@@ -228,7 +247,7 @@
a = hash_create(1031);
b = hash_create(7919);
-
+
dict = fopen("/usr/share/dict/words", "r");
if (dict == NULL) {
fprintf(stderr, "Unable to open /usr/share/dict/words - extensive testing skipped.\n");
Modified: trunk/netsurf/utils/messages.c
URL: http://svn.semichrome.net/trunk/netsurf/utils/messages.c?rev=2998&r1=2997...
==============================================================================
--- trunk/netsurf/utils/messages.c (original)
+++ trunk/netsurf/utils/messages.c Thu Oct 12 15:00:40 2006
@@ -41,9 +41,11 @@
{
char s[400];
FILE *fp;
-
+
+ assert(path != NULL);
+
ctx = (ctx != NULL) ? ctx : hash_create(HASH_SIZE);
-
+
if (ctx == NULL) {
LOG(("Unable to create hash table for messages file %s", path));
return NULL;
@@ -70,7 +72,7 @@
continue;
*colon = 0; /* terminate key */
value = colon + 1;
-
+
if (hash_add(ctx, s, value) == false) {
LOG(("Unable to add %s:%s to hash table of %s",
s, value, path));
@@ -80,7 +82,7 @@
}
fclose(fp);
-
+
return ctx;
}
@@ -99,15 +101,18 @@
{
struct hash_table *m;
char s[400];
-
+
+ assert(path != NULL);
+
m = messages_load_ctx(path, messages_hash);
if (m == NULL) {
LOG(("Unable to open Messages file '%s'. Possible reason: %s",
path, strerror(errno)));
- snprintf(s, 400, "Unable to open Messages file '%s'.", path);
+ snprintf(s, sizeof s,
+ "Unable to open Messages file '%s'.", path);
die(s);
}
-
+
messages_hash = m;
}
@@ -121,8 +126,18 @@
const char *messages_get_ctx(const char *key, struct hash_table *ctx)
{
- const char *r = hash_get(ctx, key);
-
+ const char *r;
+
+ assert(key != NULL);
+
+ /* If we're called with no context, it's nicer to return the
+ * key rather than explode - this allows attempts to get messages
+ * before messages_hash is set up to fail gracefully, for example */
+ if (ctx == NULL)
+ return key;
+
+ r = hash_get(ctx, key);
+
return r ? r : key;
}
16 years, 3 months
r2997 rjw - /trunk/netsurf/riscos/gui/status_bar.c
by netsurf@semichrome.net
Author: rjw
Date: Thu Oct 12 14:41:29 2006
New Revision: 2997
URL: http://svn.semichrome.net?rev=2997&view=rev
Log:
Don't convert text to local encoding. Correctly release all resources on destruction. Allow NULL text to clear the display. Scale progress bar for small dimensions.
Modified:
trunk/netsurf/riscos/gui/status_bar.c
Modified: trunk/netsurf/riscos/gui/status_bar.c
URL: http://svn.semichrome.net/trunk/netsurf/riscos/gui/status_bar.c?rev=2997&...
==============================================================================
--- trunk/netsurf/riscos/gui/status_bar.c (original)
+++ trunk/netsurf/riscos/gui/status_bar.c Thu Oct 12 14:41:29 2006
@@ -19,7 +19,6 @@
#include "oslib/wimpspriteop.h"
#include "netsurf/desktop/plotters.h"
#include "netsurf/utils/log.h"
-#include "netsurf/utils/utf8.h"
#include "netsurf/utils/utils.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/riscos/wimp.h"
@@ -35,7 +34,6 @@
wimp_w w; /**< status bar window handle */
wimp_w parent; /**< parent window handle */
char *text; /**< status bar text */
- char *local; /**< status bar text (local encoding) */
struct progress_bar *pb; /**< progress bar */
unsigned int scale; /**< current status bar scale */
int width; /**< current status bar width */
@@ -154,6 +152,11 @@
LOG(("xwimp_delete_window: 0x%x:%s",
error->errnum, error->errmess));
}
+
+ ro_gui_progress_bar_destroy(sb->pb);
+
+ if (sb->text)
+ free(sb->text);
free(sb);
}
@@ -289,39 +292,35 @@
* \param text the UTF8 text to display, or NULL for none
*/
void ro_gui_status_bar_set_text(struct status_bar *sb, const char *text) {
- utf8_convert_ret ret;
assert(sb);
/* check for no change */
- if ((sb->text) && (!strcmp(text, sb->text)))
- return;
-
+ if (sb->text) {
+ /* strings match */
+ if (!strcmp(text, sb->text))
+ return;
+ } else {
+ /* still no string */
+ if (!text)
+ return;
+ }
+
/* release the old text */
if (sb->text)
free(sb->text);
- sb->text = NULL;
- if (sb->local)
- free(sb->local);
- sb->local = NULL;
-
- /* copy the text */
- sb->text = strdup(text);
- if (!sb->text)
- return;
-
- /* get local encoding */
- ret = utf8_to_local_encoding(text, 0, &(sb->local));
- if (ret != UTF8_CONVERT_OK) {
- assert(ret != UTF8_CONVERT_BADENC);
- LOG(("utf8_to_enc failed"));
- free(sb->text);
- sb->text = NULL;
- return;
- }
+
+ /* copy new text if required. we don't abort on the string duplication
+ * failing as it would just cause the visible display to be out of
+ * sync with the (failed) text */
+ if (text)
+ sb->text = strdup(text);
+ else
+ sb->text = NULL;
/* redraw the window */
- xwimp_force_redraw(sb->w, 0, 0, sb->width - WIDGET_WIDTH, 65536);
+ if (sb->visible)
+ xwimp_force_redraw(sb->w, 0, 0, sb->width - WIDGET_WIDTH, 65536);
}
@@ -339,7 +338,7 @@
os_error *error;
os_box extent;
- if (!sb)
+ if ((!sb) || (!sb->visible))
return;
/* get the window work area dimensions */
@@ -451,7 +450,7 @@
}
while (more) {
/* redraw the status text */
- if (sb->local) {
+ if (sb->text) {
error = xcolourtrans_set_font_colours(font_CURRENT,
0xeeeeee00, 0x00000000, 14, 0, 0, 0);
if (error) {
@@ -462,7 +461,7 @@
code = rufl_paint(ro_gui_desktop_font_family,
ro_gui_desktop_font_style,
ro_gui_desktop_font_size,
- sb->local, strlen(sb->local),
+ sb->text, strlen(sb->text),
redraw->box.x0 + 6, redraw->box.y0 + 8,
rufl_BLEND_FONT);
if (code != rufl_OK) {
@@ -565,6 +564,7 @@
void ro_gui_status_position_progress_bar(struct status_bar *sb) {
wimp_window_state state;
os_error *error;
+ int left, right;
if (!sb)
return;
@@ -580,13 +580,17 @@
return;
}
+ /* calculate the dimensions */
+ right = state.visible.x1 - WIDGET_WIDTH - 2;
+ left = max(state.visible.x0, right - PROGRESS_WIDTH);
+
/* re-open the nested window */
state.w = ro_gui_progress_bar_get_window(sb->pb);
state.xscroll = 0;
state.yscroll = 0;
state.next = wimp_TOP;
- state.visible.x0 = state.visible.x1 - PROGRESS_WIDTH;
- state.visible.x1 -= WIDGET_WIDTH + 2;
+ state.visible.x0 = left;
+ state.visible.x1 = right;
error = xwimp_open_window_nested((wimp_open *)&state,
sb->w,
wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
@@ -605,4 +609,9 @@
LOG(("xwimp_open_window: 0x%x: %s",
error->errnum, error->errmess));
}
-}
+
+ /* update the progress bar display on non-standard width */
+ if ((right - left) != PROGRESS_WIDTH)
+ ro_gui_progress_bar_update(sb->pb, right - left,
+ state.visible.y1 - state.visible.y0);
+}
16 years, 3 months
r2996 rjw - in /trunk/netsurf/riscos/gui: progress_bar.c progress_bar.h
by netsurf@semichrome.net
Author: rjw
Date: Thu Oct 12 14:36:28 2006
New Revision: 2996
URL: http://svn.semichrome.net?rev=2996&view=rev
Log:
Allow dynamic resizing. Reverse animation direction.
Modified:
trunk/netsurf/riscos/gui/progress_bar.c
trunk/netsurf/riscos/gui/progress_bar.h
Modified: trunk/netsurf/riscos/gui/progress_bar.c
URL: http://svn.semichrome.net/trunk/netsurf/riscos/gui/progress_bar.c?rev=299...
==============================================================================
--- trunk/netsurf/riscos/gui/progress_bar.c (original)
+++ trunk/netsurf/riscos/gui/progress_bar.c Thu Oct 12 14:36:28 2006
@@ -42,9 +42,13 @@
bool recalculate; /**< recalculation required */
int cur_width; /**< current calculated width */
int cur_height; /**< current calculated height */
+ bool icon_obscured; /**< icon is partially obscured */
};
static char progress_animation_sprite[] = "progress\0";
+static osspriteop_header *progress_icon;
+static unsigned int progress_width;
+static unsigned int progress_height;
struct wimp_window_base progress_bar_definition = {
{0, 0, 1, 1},
@@ -69,12 +73,8 @@
{""},
0
};
-static osspriteop_header *progress_icon;
-static unsigned int progress_width;
-static unsigned int progress_height;
-
-
-static void ro_gui_progress_bar_update(struct progress_bar *pb);
+
+
static void ro_gui_progress_bar_calculate(struct progress_bar *pb, int width,
int height);
static void ro_gui_progress_bar_redraw(wimp_draw *redraw);
@@ -187,7 +187,7 @@
}
pb->recalculate = true;
xwimp_force_redraw(pb->w, 0, 0, 32, 32);
- ro_gui_progress_bar_update(pb);
+ ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height);
}
@@ -203,7 +203,7 @@
pb->value = value;
if (pb->value > pb->range)
pb->range = pb->value;
- ro_gui_progress_bar_update(pb);
+ ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height);
}
@@ -232,7 +232,7 @@
pb->range = range;
if (pb->value > pb->range)
pb->value = pb->range;
- ro_gui_progress_bar_update(pb);
+ ro_gui_progress_bar_update(pb, pb->cur_width, pb->cur_height);
}
@@ -250,15 +250,21 @@
/**
- * Update the display to reflect new values
+ * Update the progress bar to a new dimension.
*
* \param pb the progress bar to update
- */
-void ro_gui_progress_bar_update(struct progress_bar *pb) {
+ * \param width the new progress bar width
+ * \param height the new progress bar height
+ */
+void ro_gui_progress_bar_update(struct progress_bar *pb, int width, int height) {
wimp_draw redraw;
os_error *error;
osbool more;
os_box cur;
+
+ /* don't allow negative dimensions */
+ width = max(width, 0);
+ height = max(height, 0);
/* update the animation state */
if ((pb->value == 0) || (pb->value == pb->range)) {
@@ -274,7 +280,7 @@
/* get old and new positions */
cur = pb->visible;
pb->recalculate = true;
- ro_gui_progress_bar_calculate(pb, pb->cur_width, pb->cur_height);
+ ro_gui_progress_bar_calculate(pb, width, height);
/* see if the progress bar hasn't moved. we don't need to consider
* the left edge moving as this is handled by the icon setting
@@ -365,6 +371,7 @@
int icon_width, icon_height;
int icon_x0 = 0, icon_y0 = 0, progress_x0, progress_x1, progress_ymid = 0;
osspriteop_header *icon = NULL;
+ bool icon_redraw = false;
/* try to use cached values */
if ((!pb->recalculate) && (pb->cur_width == width) &&
@@ -396,8 +403,20 @@
width -= 32;
icon_x0 = 16 - icon_width;
icon_y0 = progress_ymid - icon_height;
+ if (width < 0) {
+ icon_x0 += width;
+ icon_redraw = true;
+ }
}
}
+
+ /* update the icon */
+ if ((pb->icon_obscured) || (icon_redraw)) {
+ if (icon_x0 != pb->icon_x0)
+ xwimp_force_redraw(pb->w, 0, 0, 32, 32);
+ }
+ pb->icon_obscured = icon_redraw;
+
progress_x1 = progress_x0;
if (pb->range > 0)
progress_x1 += (width * pb->value) / pb->range;
@@ -439,7 +458,7 @@
/* redraw the window */
while (more) {
if (pb->icon)
- _swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
+ _swix(Tinct_PlotAlpha, _IN(2) | _IN(3) | _IN(4) | _IN(7),
pb->icon_img,
redraw->box.x0 + pb->icon_x0,
redraw->box.y0 + pb->icon_y0,
@@ -458,7 +477,7 @@
clip_x1, clip_y1);
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
progress_icon,
- redraw->box.x0 + pb->offset,
+ redraw->box.x0 - pb->offset,
progress_ymid - progress_height,
tinct_FILL_HORIZONTALLY);
}
Modified: trunk/netsurf/riscos/gui/progress_bar.h
URL: http://svn.semichrome.net/trunk/netsurf/riscos/gui/progress_bar.h?rev=299...
==============================================================================
--- trunk/netsurf/riscos/gui/progress_bar.h (original)
+++ trunk/netsurf/riscos/gui/progress_bar.h Thu Oct 12 14:36:28 2006
@@ -22,6 +22,7 @@
struct progress_bar *ro_gui_progress_bar_create(void);
void ro_gui_progress_bar_destroy(struct progress_bar *pb);
+void ro_gui_progress_bar_update(struct progress_bar *pb, int width, int height);
wimp_w ro_gui_progress_bar_get_window(struct progress_bar *pb);
void ro_gui_progress_bar_set_icon(struct progress_bar *pb, const char *icon);
16 years, 3 months
r2995 rjw - in /trunk/netsurf/riscos/gui: status_bar.c status_bar.h
by netsurf@semichrome.net
Author: rjw
Date: Thu Oct 12 00:25:02 2006
New Revision: 2995
URL: http://svn.semichrome.net?rev=2995&view=rev
Log:
UTF-8 status bar component.
Added:
trunk/netsurf/riscos/gui/status_bar.c
trunk/netsurf/riscos/gui/status_bar.h
Added: trunk/netsurf/riscos/gui/status_bar.c
URL: http://svn.semichrome.net/trunk/netsurf/riscos/gui/status_bar.c?rev=2995&...
==============================================================================
--- trunk/netsurf/riscos/gui/status_bar.c (added)
+++ trunk/netsurf/riscos/gui/status_bar.c Thu Oct 12 00:25:02 2006
@@ -1,0 +1,608 @@
+/*
+ * 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 2006 Richard Wilson <info(a)tinct.net>
+ */
+
+/** \file
+ * UTF8 status bar (implementation).
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <string.h>
+#include <swis.h>
+#include "oslib/colourtrans.h"
+#include "oslib/os.h"
+#include "oslib/wimp.h"
+#include "oslib/wimpspriteop.h"
+#include "netsurf/desktop/plotters.h"
+#include "netsurf/utils/log.h"
+#include "netsurf/utils/utf8.h"
+#include "netsurf/utils/utils.h"
+#include "netsurf/riscos/gui.h"
+#include "netsurf/riscos/wimp.h"
+#include "netsurf/riscos/wimp_event.h"
+#include "netsurf/riscos/gui/progress_bar.h"
+#include "netsurf/riscos/gui/status_bar.h"
+
+#define ICON_WIDGET 0
+#define WIDGET_WIDTH 12
+#define PROGRESS_WIDTH 160
+
+struct status_bar {
+ wimp_w w; /**< status bar window handle */
+ wimp_w parent; /**< parent window handle */
+ char *text; /**< status bar text */
+ char *local; /**< status bar text (local encoding) */
+ struct progress_bar *pb; /**< progress bar */
+ unsigned int scale; /**< current status bar scale */
+ int width; /**< current status bar width */
+ bool visible; /**< status bar is visible? */
+};
+
+static char status_widget_text[] = "\0";
+static char status_widget_validation[] = "R5;Pptr_lr,8,6\0";
+
+wimp_WINDOW(1) status_bar_definition = {
+ {0, 0, 1, 1},
+ 0,
+ 0,
+ wimp_TOP,
+ wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_MOVEABLE |
+ wimp_WINDOW_FURNITURE_WINDOW |
+ wimp_WINDOW_IGNORE_XEXTENT,
+ wimp_COLOUR_BLACK,
+ wimp_COLOUR_LIGHT_GREY,
+ wimp_COLOUR_LIGHT_GREY,
+ wimp_COLOUR_VERY_LIGHT_GREY,
+ wimp_COLOUR_DARK_GREY,
+ wimp_COLOUR_MID_LIGHT_GREY,
+ wimp_COLOUR_CREAM,
+ wimp_WINDOW_NEVER3D | 0x16u /* RISC OS 5.03+ */,
+ {0, 0, 65535, 65535},
+ 0,
+ 0,
+ wimpspriteop_AREA,
+ 1,
+ 1,
+ {""},
+ 1,
+ {
+ {
+ {0, 0, 1, 1},
+ wimp_ICON_TEXT | wimp_ICON_INDIRECTED |
+ wimp_ICON_BORDER | wimp_ICON_FILLED |
+ (wimp_COLOUR_LIGHT_GREY <<
+ wimp_ICON_BG_COLOUR_SHIFT) |
+ (wimp_BUTTON_CLICK_DRAG <<
+ wimp_ICON_BUTTON_TYPE_SHIFT),
+ {
+ .indirected_text = {
+ status_widget_text,
+ status_widget_validation,
+ 1
+ }
+ }
+ }
+ }
+};
+
+static void ro_gui_status_bar_open(wimp_open *open);
+static bool ro_gui_status_bar_click(wimp_pointer *pointer);
+static void ro_gui_status_bar_redraw(wimp_draw *redraw);
+static void ro_gui_status_position_progress_bar(struct status_bar *sb);
+
+
+/**
+ * Create a new status bar
+ *
+ * \param parent the window to contain the status bar
+ * \param width the proportional width to use (0...10,000)
+ */
+struct status_bar *ro_gui_status_bar_create(wimp_w parent, unsigned int width) {
+ struct status_bar *sb;
+ os_error *error;
+
+ sb = calloc(1, sizeof(*sb));
+ if (!sb)
+ return NULL;
+
+ sb->pb = ro_gui_progress_bar_create();
+ if (!sb->pb)
+ return NULL;
+
+ error = xwimp_create_window((wimp_window *)&status_bar_definition,
+ &sb->w);
+ if (error) {
+ LOG(("xwimp_create_window: 0x%x: %s",
+ error->errnum, error->errmess));
+ free(sb);
+ return NULL;
+ }
+ sb->parent = parent;
+ sb->scale = width;
+ sb->visible = true;
+
+ ro_gui_wimp_event_set_user_data(sb->w, sb);
+ ro_gui_wimp_event_register_open_window(sb->w,
+ ro_gui_status_bar_open);
+ ro_gui_wimp_event_register_mouse_click(sb->w,
+ ro_gui_status_bar_click);
+ ro_gui_wimp_event_register_redraw_window(sb->w,
+ ro_gui_status_bar_redraw);
+ ro_gui_wimp_event_set_user_data(sb->w, sb);
+ ro_gui_wimp_event_set_help_prefix(sb->w, "HelpStatus");
+ ro_gui_status_bar_resize(sb);
+ return sb;
+}
+
+
+/**
+ * Destroy a status bar and free all associated resources
+ *
+ * \param sb the status bar to destroy
+ */
+void ro_gui_status_bar_destroy(struct status_bar *sb) {
+ os_error *error;
+ assert(sb);
+
+ ro_gui_wimp_event_finalise(sb->w);
+ error = xwimp_delete_window(sb->w);
+ if (error) {
+ LOG(("xwimp_delete_window: 0x%x:%s",
+ error->errnum, error->errmess));
+ }
+
+ free(sb);
+}
+
+
+/**
+ * Get the handle of the window that represents a status bar
+ *
+ * \param sb the status bar to get the window handle of
+ * \return the status bar's window handle
+ */
+wimp_w ro_gui_status_bar_get_window(struct status_bar *sb) {
+ assert(sb);
+
+ return sb->w;
+}
+
+
+/**
+ * Get the proportional width the status bar is currently using
+ *
+ * \param sb the status bar to get the width of
+ * \return the status bar's width (0...10,000)
+ */
+unsigned int ro_gui_status_bar_get_width(struct status_bar *sb) {
+ assert(sb);
+
+ return sb->scale;
+}
+
+
+/**
+ * Get the visibility status of the status bar
+ *
+ * \param sb the status bar to check the visiblity of
+ * \return whether the status bar is visible
+ */
+void ro_gui_status_bar_set_visible(struct status_bar *sb, bool visible) {
+ os_error *error;
+
+ assert(sb);
+
+ sb->visible = visible;
+ if (visible) {
+ ro_gui_status_bar_resize(sb);
+ } else {
+ error = xwimp_close_window(sb->w);
+ if (error) {
+ LOG(("xwimp_close_window: 0x%x:%s",
+ error->errnum, error->errmess));
+ }
+ }
+}
+
+
+/**
+ * Get the visibility status of the status bar
+ *
+ * \param sb the status bar to check the visiblity of
+ * \return whether the status bar is visible
+ */
+bool ro_gui_status_bar_get_visible(struct status_bar *sb) {
+ assert(sb);
+
+ return sb->visible;
+}
+
+
+/**
+ * Set the value of the progress bar
+ *
+ * \param pb the status bar to set the progress of
+ * \param value the value to use
+ */
+void ro_gui_status_bar_set_progress_value(struct status_bar *sb,
+ unsigned int value) {
+
+ assert(sb);
+
+ ro_gui_status_bar_set_progress_range(sb,
+ max(value, ro_gui_progress_bar_get_range(sb->pb)));
+ ro_gui_progress_bar_set_value(sb->pb, value);
+}
+
+
+/**
+ * Set the range of the progress bar
+ *
+ * \param pb the status bar to set the range of
+ * \param value the value to use, or 0 to turn off the progress bar
+ */
+void ro_gui_status_bar_set_progress_range(struct status_bar *sb,
+ unsigned int range) {
+ unsigned int old_range;
+ os_error *error;
+
+ assert(sb);
+
+ old_range = ro_gui_progress_bar_get_range(sb->pb);
+ ro_gui_progress_bar_set_range(sb->pb, range);
+
+ LOG(("Ranges are %i vs %i", old_range, range));
+ if ((old_range == 0) && (range != 0)) {
+ ro_gui_status_position_progress_bar(sb);
+ } else if ((old_range != 0) && (range == 0)) {
+ error = xwimp_close_window(
+ ro_gui_progress_bar_get_window(sb->pb));
+ if (error) {
+ LOG(("xwimp_close_window: 0x%x:%s",
+ error->errnum, error->errmess));
+ }
+ }
+}
+
+
+/**
+ * Set the icon for the progress bar
+ *
+ * \param pb the status bar to set the icon for
+ * \param icon the icon to use, or NULL for no icon
+ */
+void ro_gui_status_bar_set_progress_icon(struct status_bar *sb,
+ const char *icon) {
+ assert(sb);
+
+ ro_gui_progress_bar_set_icon(sb->pb, icon);
+}
+
+
+/**
+ * Set the text to display in the status bar
+ *
+ * \param text the UTF8 text to display, or NULL for none
+ */
+void ro_gui_status_bar_set_text(struct status_bar *sb, const char *text) {
+ utf8_convert_ret ret;
+
+ assert(sb);
+
+ /* check for no change */
+ if ((sb->text) && (!strcmp(text, sb->text)))
+ return;
+
+ /* release the old text */
+ if (sb->text)
+ free(sb->text);
+ sb->text = NULL;
+ if (sb->local)
+ free(sb->local);
+ sb->local = NULL;
+
+ /* copy the text */
+ sb->text = strdup(text);
+ if (!sb->text)
+ return;
+
+ /* get local encoding */
+ ret = utf8_to_local_encoding(text, 0, &(sb->local));
+ if (ret != UTF8_CONVERT_OK) {
+ assert(ret != UTF8_CONVERT_BADENC);
+ LOG(("utf8_to_enc failed"));
+ free(sb->text);
+ sb->text = NULL;
+ return;
+ }
+
+ /* redraw the window */
+ xwimp_force_redraw(sb->w, 0, 0, sb->width - WIDGET_WIDTH, 65536);
+}
+
+
+/**
+ * Resize a status bar following a change in the dimensions of the
+ * parent window.
+ *
+ * \param sb the status bar to resize
+ */
+void ro_gui_status_bar_resize(struct status_bar *sb) {
+ int window_width, window_height;
+ int status_width, status_height;
+ int redraw_left, redraw_right;
+ wimp_window_state state;
+ os_error *error;
+ os_box extent;
+
+ if (!sb)
+ return;
+
+ /* get the window work area dimensions */
+ state.w = sb->parent;
+ error = xwimp_get_window_state(&state);
+ if (error) {
+ LOG(("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+ window_width = state.visible.x1 - state.visible.x0;
+ window_height = state.visible.y1 - state.visible.y0;
+
+
+ /* recalculate the scaled width */
+ status_width = (window_width * sb->scale) / 10000;
+ if (status_width < WIDGET_WIDTH)
+ status_width = WIDGET_WIDTH;
+ status_height = ro_get_hscroll_height(sb->parent);
+
+ /* resize the status/resize icons */
+ if (status_width != sb->width) {
+ /* update the window extent */
+ extent.x0 = 0;
+ extent.y0 = 0;
+ extent.x1 = status_width;
+ extent.y1 = status_height - 4;
+ error = xwimp_set_extent(sb->w, &extent);
+ if (error) {
+ LOG(("xwimp_set_extent: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+
+ /* re-open the nested window */
+ state.w = sb->w;
+ state.xscroll = 0;
+ state.yscroll = 0;
+ state.next = wimp_TOP;
+ state.visible.x0 = state.visible.x0;
+ state.visible.y1 = state.visible.y0 - 2;
+ state.visible.x1 = state.visible.x0 + status_width;
+ state.visible.y0 = state.visible.y1 - status_height + 4;
+ error = xwimp_open_window_nested((wimp_open *)&state,
+ sb->parent,
+ 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_BOTTOM_OR_LEFT
+ << wimp_CHILD_RS_EDGE_SHIFT |
+ wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
+ << wimp_CHILD_TS_EDGE_SHIFT);
+ if (error) {
+ LOG(("xwimp_open_window_nested: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+ ro_gui_status_position_progress_bar(sb);
+ error = xwimp_resize_icon(sb->w, ICON_WIDGET,
+ status_width - WIDGET_WIDTH, 0,
+ status_width, status_height - 4);
+ if (error) {
+ LOG(("xwimp_resize_icon: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+
+ redraw_left = min(status_width, sb->width) - WIDGET_WIDTH - 2;
+ redraw_right = max(status_width, sb->width);
+ xwimp_force_redraw(sb->w, redraw_left, 0,
+ redraw_right, status_height);
+ sb->width = status_width;
+ }
+}
+
+
+/**
+ * Process a WIMP redraw request
+ *
+ * \param redraw the redraw request to process
+ */
+void ro_gui_status_bar_redraw(wimp_draw *redraw) {
+
+ struct status_bar *sb;
+ os_error *error;
+ osbool more;
+ rufl_code code;
+
+ sb = (struct status_bar *)ro_gui_wimp_event_get_user_data(redraw->w);
+ assert(sb);
+
+ /* initialise the plotters */
+ plot = ro_plotters;
+ ro_plot_set_scale(1.0);
+ ro_plot_origin_x = 0;
+ ro_plot_origin_y = 0;
+
+ /* redraw the window */
+ error = xwimp_redraw_window(redraw, &more);
+ if (error) {
+ LOG(("xwimp_redraw_window: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+ while (more) {
+ /* redraw the status text */
+ if (sb->local) {
+ error = xcolourtrans_set_font_colours(font_CURRENT,
+ 0xeeeeee00, 0x00000000, 14, 0, 0, 0);
+ if (error) {
+ LOG(("xcolourtrans_set_font_colours: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+ code = rufl_paint(ro_gui_desktop_font_family,
+ ro_gui_desktop_font_style,
+ ro_gui_desktop_font_size,
+ sb->local, strlen(sb->local),
+ redraw->box.x0 + 6, redraw->box.y0 + 8,
+ rufl_BLEND_FONT);
+ if (code != rufl_OK) {
+ if (code == rufl_FONT_MANAGER_ERROR)
+ LOG(("rufl_FONT_MANAGER_ERROR: 0x%x: %s",
+ rufl_fm_error->errnum,
+ rufl_fm_error->errmess));
+ else
+ LOG(("rufl_paint: 0x%x", code));
+ }
+ }
+
+ /* separate the widget from the text with a line */
+ plot.fill((redraw->box.x0 + sb->width - WIDGET_WIDTH - 2) >> 1,
+ -redraw->box.y0 >> 1,
+ (redraw->box.x0 + sb->width - WIDGET_WIDTH) >> 1,
+ -redraw->box.y1 >> 1,
+ 0x00000000);
+
+ error = xwimp_get_rectangle(redraw, &more);
+ if (error) {
+ LOG(("xwimp_get_rectangle: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+ }
+}
+
+
+/**
+ * Process an mouse_click event for a status window.
+ *
+ * \param pointer details of the mouse click
+ */
+bool ro_gui_status_bar_click(wimp_pointer *pointer) {
+ wimp_drag drag;
+ os_error *error;
+
+ switch (pointer->i) {
+ case ICON_WIDGET:
+ gui_current_drag_type = GUI_DRAG_STATUS_RESIZE;
+ drag.w = pointer->w;
+ drag.type = wimp_DRAG_SYSTEM_SIZE;
+ drag.initial.x0 = pointer->pos.x;
+ drag.initial.x1 = pointer->pos.x;
+ drag.initial.y0 = pointer->pos.y;
+ drag.initial.y1 = pointer->pos.y;
+ error = xwimp_drag_box(&drag);
+ if (error) {
+ LOG(("xwimp_drag_box: 0x%x: %s",
+ error->errnum, error->errmess));
+ }
+ break;
+ }
+ return true;
+}
+
+
+/**
+ * Process an open_window request for a status window.
+ *
+ * \param open the request to process
+ */
+void ro_gui_status_bar_open(wimp_open *open) {
+ struct status_bar *sb;
+ int window_width, status_width;
+ wimp_window_state state;
+ os_error *error;
+
+ /* get the parent width for scaling */
+ sb = (struct status_bar *)ro_gui_wimp_event_get_user_data(open->w);
+ state.w = sb->parent;
+ error = xwimp_get_window_state(&state);
+ if (error) {
+ LOG(("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+ window_width = state.visible.x1 - state.visible.x0;
+ if (window_width == 0)
+ window_width = 1;
+ status_width = open->visible.x1 - open->visible.x0;
+ if (status_width <= 12)
+ status_width = 0;
+
+ /* store the new size */
+ sb->scale = (10000 * status_width) / window_width;
+ if (sb->scale > 10000)
+ sb->scale = 10000;
+ ro_gui_status_bar_resize(sb);
+}
+
+
+/**
+ * Reposition the progress component following a change in the
+ * dimension of the status window.
+ *
+ * \param sb the status bar to update
+ */
+void ro_gui_status_position_progress_bar(struct status_bar *sb) {
+ wimp_window_state state;
+ os_error *error;
+
+ if (!sb)
+ return;
+ if (ro_gui_progress_bar_get_range(sb->pb) == 0)
+ return;
+
+ /* get the window work area dimensions */
+ state.w = sb->w;
+ error = xwimp_get_window_state(&state);
+ if (error) {
+ LOG(("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess));
+ return;
+ }
+
+ /* re-open the nested window */
+ state.w = ro_gui_progress_bar_get_window(sb->pb);
+ state.xscroll = 0;
+ state.yscroll = 0;
+ state.next = wimp_TOP;
+ state.visible.x0 = state.visible.x1 - PROGRESS_WIDTH;
+ state.visible.x1 -= WIDGET_WIDTH + 2;
+ error = xwimp_open_window_nested((wimp_open *)&state,
+ sb->w,
+ 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_BOTTOM_OR_LEFT
+ << wimp_CHILD_RS_EDGE_SHIFT |
+ wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
+ << wimp_CHILD_TS_EDGE_SHIFT);
+ if (error) {
+ LOG(("xwimp_open_window: 0x%x: %s",
+ error->errnum, error->errmess));
+ }
+}
Added: trunk/netsurf/riscos/gui/status_bar.h
URL: http://svn.semichrome.net/trunk/netsurf/riscos/gui/status_bar.h?rev=2995&...
==============================================================================
--- trunk/netsurf/riscos/gui/status_bar.h (added)
+++ trunk/netsurf/riscos/gui/status_bar.h Thu Oct 12 00:25:02 2006
@@ -1,0 +1,34 @@
+/*
+ * 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 2006 Richard Wilson <info(a)tinct.net>
+ */
+
+/** \file
+ * UTF8 status bar (interface).
+ */
+
+#include <stdbool.h>
+
+#ifndef _NETSURF_RISCOS_STATUS_BAR_H_
+#define _NETSURF_RISCOS_STATUS_BAR_H_
+
+struct status_bar;
+
+struct status_bar *ro_gui_status_bar_create(wimp_w parent, unsigned int width);
+void ro_gui_status_bar_destroy(struct status_bar *sb);
+
+wimp_w ro_gui_status_bar_get_window(struct status_bar *sb);
+unsigned int ro_gui_status_bar_get_width(struct status_bar *sb);
+void ro_gui_status_bar_resize(struct status_bar *sb);
+void ro_gui_status_bar_set_visible(struct status_bar *pb, bool visible);
+bool ro_gui_status_bar_get_visible(struct status_bar *pb);
+void ro_gui_status_bar_set_text(struct status_bar *pb, const char *text);
+void ro_gui_status_bar_set_progress_value(struct status_bar *sb,
+ unsigned int value);
+void ro_gui_status_bar_set_progress_range(struct status_bar *sb,
+ unsigned int range);
+void ro_gui_status_bar_set_progress_icon(struct status_bar *sb,
+ const char *icon);
+#endif
16 years, 3 months
r2994 rjw - in /trunk/netsurf/riscos/gui: progress_bar.c progress_bar.h
by netsurf@semichrome.net
Author: rjw
Date: Thu Oct 12 00:23:40 2006
New Revision: 2994
URL: http://svn.semichrome.net?rev=2994&view=rev
Log:
Fix redraw when no sprites are present. Squash compiler warnings.
Modified:
trunk/netsurf/riscos/gui/progress_bar.c
trunk/netsurf/riscos/gui/progress_bar.h
Modified: trunk/netsurf/riscos/gui/progress_bar.c
URL: http://svn.semichrome.net/trunk/netsurf/riscos/gui/progress_bar.c?rev=299...
==============================================================================
--- trunk/netsurf/riscos/gui/progress_bar.c (original)
+++ trunk/netsurf/riscos/gui/progress_bar.c Thu Oct 12 00:23:40 2006
@@ -43,6 +43,8 @@
int cur_width; /**< current calculated width */
int cur_height; /**< current calculated height */
};
+
+static char progress_animation_sprite[] = "progress\0";
struct wimp_window_base progress_bar_definition = {
{0, 0, 1, 1},
@@ -94,11 +96,11 @@
progress_icon = NULL;
error = xosspriteop_select_sprite(osspriteop_USER_AREA,
progress_bar_definition.sprite_area,
- (osspriteop_id)"progress", &progress_icon);
+ (osspriteop_id)progress_animation_sprite, &progress_icon);
if (!error) {
xosspriteop_read_sprite_info(osspriteop_USER_AREA,
progress_bar_definition.sprite_area,
- (osspriteop_id)"progress",
+ (osspriteop_id)progress_animation_sprite,
&progress_width, &progress_height, 0, 0);
}
}
@@ -461,11 +463,11 @@
tinct_FILL_HORIZONTALLY);
}
} else {
- plot.fill(redraw->box.x0 + pb->visible.x0,
- redraw->box.y0 + pb->visible.y0,
- redraw->box.x0 + pb->visible.x1,
- redraw->box.y0 + pb->visible.y1,
- 0xff000000);
+ plot.fill((redraw->box.x0 + pb->visible.x0) >> 1,
+ -(redraw->box.y0 + pb->visible.y0) >> 1,
+ (redraw->box.x0 + pb->visible.x1) >> 1,
+ -(redraw->box.y0 + pb->visible.y1) >> 1,
+ 0x000000ff);
}
error = xwimp_get_rectangle(redraw, &more);
if (error) {
Modified: trunk/netsurf/riscos/gui/progress_bar.h
URL: http://svn.semichrome.net/trunk/netsurf/riscos/gui/progress_bar.h?rev=299...
==============================================================================
--- trunk/netsurf/riscos/gui/progress_bar.h (original)
+++ trunk/netsurf/riscos/gui/progress_bar.h Thu Oct 12 00:23:40 2006
@@ -29,5 +29,4 @@
unsigned int ro_gui_progress_bar_get_value(struct progress_bar *pb);
void ro_gui_progress_bar_set_range(struct progress_bar *pb, unsigned int range);
unsigned int ro_gui_progress_bar_get_range(struct progress_bar *pb);
-void ro_gui_progress_bar_set_visible(struct progress_bar *pb, bool visible);
#endif
16 years, 3 months
r2993 tlsa - /trunk/netsurftest/haveproblems/inline-background-position.html
by netsurf@semichrome.net
Author: tlsa
Date: Wed Oct 11 11:06:06 2006
New Revision: 2993
URL: http://svn.semichrome.net?rev=2993&view=rev
Log:
Update image links.
Modified:
trunk/netsurftest/haveproblems/inline-background-position.html
Modified: trunk/netsurftest/haveproblems/inline-background-position.html
URL: http://svn.semichrome.net/trunk/netsurftest/haveproblems/inline-backgroun...
==============================================================================
--- trunk/netsurftest/haveproblems/inline-background-position.html (original)
+++ trunk/netsurftest/haveproblems/inline-background-position.html Wed Oct 11 11:06:06 2006
@@ -1,8 +1,8 @@
<html>
<head>
<style>
-.phase { background: url(phase.gif) right no-repeat; padding: 0 1.5em 0 0; }
-.potm { background: url(potm.gif) right no-repeat; padding: 0 1.5em 0 0; }
+.phase { background: url(../images/phase.gif) right no-repeat; padding: 0 1.5em 0 0; }
+.potm { background: url(../images/potm.gif) right no-repeat; padding: 0 1.5em 0 0; }
</style>
</head>
<body>
16 years, 3 months