[project @ 2004-05-06 20:37:48 by bursa]

Remove obsolete theme files. Hide some unimplemented toolbar icons. F2 moves caret to URL bar and clears it to "www.". Simplify some of the toolbar code. Fix menu-related crash (reported by Jerome Mathevet).

svn path=/import/netsurf/; revision=836
This commit is contained in:
James Bursa 2004-05-06 20:37:48 +00:00
parent c0a4ab450b
commit 7cb9b4d79b
7 changed files with 95 additions and 92 deletions

Binary file not shown.

View File

@ -632,8 +632,7 @@ void ro_gui_build_theme_menu(void)
continue; continue;
if (info.obj_type != fileswitch_IS_DIR) if (info.obj_type != fileswitch_IS_DIR)
continue; continue;
if (!(file_exists(THEMES_DIR, info.name, "Templates", 0xfec) && if (!file_exists(THEMES_DIR, info.name, "Sprites", 0xff9))
file_exists(THEMES_DIR, info.name, "Sprites", 0xff9)))
continue; continue;
theme_menu = xrealloc(theme_menu, wimp_SIZEOF_MENU(i + 1)); theme_menu = xrealloc(theme_menu, wimp_SIZEOF_MENU(i + 1));
@ -654,7 +653,19 @@ void ro_gui_build_theme_menu(void)
i++; i++;
} }
assert(i != 0); if (i == 0) {
theme_menu->entries[0].menu_flags = 0;
theme_menu->entries[0].sub_menu = wimp_NO_SUB_MENU;
theme_menu->entries[0].icon_flags = wimp_ICON_TEXT |
wimp_ICON_FILLED | wimp_ICON_INDIRECTED |
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) |
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT) |
wimp_ICON_SHADED;
theme_menu->entries[0].data.indirected_text.text = xstrdup("-");
theme_menu->entries[0].data.indirected_text.validation = (char*)-1;
theme_menu->entries[0].data.indirected_text.size = 2;
i = 1;
}
entries = i; entries = i;
theme_menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED; theme_menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED;

View File

@ -43,7 +43,7 @@ static void ro_gui_menu_prepare_images(void);
static void ro_gui_menu_prepare_toolbars(void); static void ro_gui_menu_prepare_toolbars(void);
static void ro_gui_menu_pageinfo(wimp_message_menu_warning *warning); static void ro_gui_menu_pageinfo(wimp_message_menu_warning *warning);
static void ro_gui_menu_objectinfo(wimp_message_menu_warning *warning); static void ro_gui_menu_objectinfo(wimp_message_menu_warning *warning);
static struct box *find_object_box(void); static struct box *ro_gui_menu_find_object_box(void);
static wimp_menu *current_menu; static wimp_menu *current_menu;
static int current_menu_x, current_menu_y; static int current_menu_x, current_menu_y;
@ -343,15 +343,11 @@ void ro_gui_create_menu(wimp_menu *menu, int x, int y, gui_window *g)
current_menu_x = x; current_menu_x = x;
current_menu_y = y; current_menu_y = y;
current_gui = g; current_gui = g;
if (menu != iconbar_menu) { if (menu == browser_menu) {
if (find_object_box() == NULL && menu == browser_menu) { if (ro_gui_menu_find_object_box())
menu->entries[1].sub_menu = (wimp_menu*)1; menu->entries[1].icon_flags &= ~wimp_ICON_SHADED;
menu->entries[1].icon_flags |= wimp_ICON_SHADED; else
} menu->entries[1].icon_flags |= wimp_ICON_SHADED;
else if (menu == browser_menu) {
menu->entries[1].sub_menu = (wimp_menu*)&object_menu;
menu->entries[1].icon_flags &= ~wimp_ICON_SHADED;
}
} }
wimp_create_menu(menu, x, y); wimp_create_menu(menu, x, y);
} }
@ -656,7 +652,7 @@ void ro_gui_menu_warning(wimp_message_menu_warning *warning)
} }
break; break;
} }
struct box *box = find_object_box(); struct box *box = ro_gui_menu_find_object_box();
if (box) { if (box) {
ro_gui_menu_prepare_save(box->object); ro_gui_menu_prepare_save(box->object);
error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas, error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas,
@ -865,7 +861,7 @@ void ro_gui_menu_objectinfo(wimp_message_menu_warning *warning)
const char *target = "-"; const char *target = "-";
const char *mime = "-"; const char *mime = "-";
box = find_object_box(); box = ro_gui_menu_find_object_box();
if (box) { if (box) {
sprintf(icon_buf, "file_%x", ro_content_filetype(box->object)); sprintf(icon_buf, "file_%x", ro_content_filetype(box->object));
if (box->object->url) url = box->object->url; if (box->object->url) url = box->object->url;
@ -893,7 +889,7 @@ void ro_gui_menu_objectinfo(wimp_message_menu_warning *warning)
} }
} }
struct box *find_object_box(void) struct box *ro_gui_menu_find_object_box(void)
{ {
struct content *c = current_gui->data.browser.bw->current_content; struct content *c = current_gui->data.browser.bw->current_content;
struct box_selection *boxes = NULL; struct box_selection *boxes = NULL;

View File

@ -21,6 +21,31 @@
#include "netsurf/riscos/wimp.h" #include "netsurf/riscos/wimp.h"
#include "netsurf/utils/log.h" #include "netsurf/utils/log.h"
struct toolbar_icon {
/* The desired WIMP icon number (-1 for separator)
*/
int icon_number;
/* Set to non-zero to display the icon
*/
unsigned int available;
/* Icon dimensions (OS units)
*/
unsigned int width;
unsigned int height;
/* Icon validation string
*/
char validation[40];
/* The next icon (linked list)
*/
struct toolbar_icon *next_icon; // Next toolbar icon
};
/* A basic window for the toolbar and status /* A basic window for the toolbar and status
*/ */
static wimp_window empty_window = { static wimp_window empty_window = {
@ -53,14 +78,15 @@ static wimp_icon_create empty_icon;
/* Shared URL validation /* Shared URL validation
*/ */
static char *url_validation = "Pptr_write\0"; static char url_validation[] = "Pptr_write\0";
static char *resize_validation = "R1;Pptr_lr,8,6\0"; static char resize_validation[] = "R1;Pptr_lr,8,6\0";
static char *null_text_string = "\0"; static char null_text_string[] = "\0";
static struct toolbar *ro_toolbar_create_icons(struct toolbar *toolbar, osspriteop_area *sprite_area, static struct toolbar *ro_toolbar_create_icons(struct toolbar *toolbar, osspriteop_area *sprite_area,
char *url_buffer, char *throbber_buffer); char *url_buffer, char *throbber_buffer);
static struct toolbar_icon *ro_toolbar_create_icon(osspriteop_area *sprite_area, char *sprite, unsigned int icon); static struct toolbar_icon *ro_toolbar_initialise_icon(osspriteop_area *sprite_area,
const char *sprite, unsigned int icon);
static struct toolbar_icon *ro_toolbar_create_separator(void); static struct toolbar_icon *ro_toolbar_create_separator(void);
static void ro_toolbar_destroy_icon(struct toolbar_icon *icon); static void ro_toolbar_destroy_icon(struct toolbar_icon *icon);
static void ro_toolbar_add_icon(struct toolbar *toolbar, struct toolbar_icon *icon); static void ro_toolbar_add_icon(struct toolbar *toolbar, struct toolbar_icon *icon);
@ -89,20 +115,20 @@ struct toolbar *ro_toolbar_create(osspriteop_area *sprite_area, char *url_buffer
/* Load the toolbar icons /* Load the toolbar icons
*/ */
if (sprite_area) { if (sprite_area) {
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "back", ICON_TOOLBAR_BACK)); ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "back", ICON_TOOLBAR_BACK));
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "forward", ICON_TOOLBAR_FORWARD)); ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "forward", ICON_TOOLBAR_FORWARD));
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "stop", ICON_TOOLBAR_STOP)); ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "stop", ICON_TOOLBAR_STOP));
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "reload", ICON_TOOLBAR_RELOAD)); ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "reload", ICON_TOOLBAR_RELOAD));
ro_toolbar_add_icon(toolbar, ro_toolbar_create_separator()); ro_toolbar_add_icon(toolbar, ro_toolbar_create_separator());
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "home", ICON_TOOLBAR_HOME)); /* ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "home", ICON_TOOLBAR_HOME)); */
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "up", ICON_TOOLBAR_UP)); /* ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "up", ICON_TOOLBAR_UP)); */
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "search", ICON_TOOLBAR_SEARCH)); /* ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "search", ICON_TOOLBAR_SEARCH)); */
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "history", ICON_TOOLBAR_HISTORY)); ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "history", ICON_TOOLBAR_HISTORY));
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "scale", ICON_TOOLBAR_SCALE)); ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "scale", ICON_TOOLBAR_SCALE));
ro_toolbar_add_icon(toolbar, ro_toolbar_create_separator()); ro_toolbar_add_icon(toolbar, ro_toolbar_create_separator());
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "mark", ICON_TOOLBAR_BOOKMARK)); /* ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "mark", ICON_TOOLBAR_BOOKMARK)); */
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "save", ICON_TOOLBAR_SAVE)); ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "save", ICON_TOOLBAR_SAVE));
ro_toolbar_add_icon(toolbar, ro_toolbar_create_icon(sprite_area, "print", ICON_TOOLBAR_PRINT)); /* ro_toolbar_add_icon(toolbar, ro_toolbar_initialise_icon(sprite_area, "print", ICON_TOOLBAR_PRINT)); */
} }
/* Set the sprite area /* Set the sprite area
@ -110,7 +136,7 @@ struct toolbar *ro_toolbar_create(osspriteop_area *sprite_area, char *url_buffer
if (sprite_area) { if (sprite_area) {
empty_window.sprite_area = sprite_area; empty_window.sprite_area = sprite_area;
} else { } else {
empty_window.sprite_area = 1; empty_window.sprite_area = (osspriteop_area *) 1;
} }
/* Create the basic windows /* Create the basic windows
@ -241,7 +267,7 @@ static struct toolbar *ro_toolbar_create_icons(struct toolbar *toolbar, ossprite
if (sprite_area) { if (sprite_area) {
empty_icon.icon.data.indirected_sprite.area = sprite_area; empty_icon.icon.data.indirected_sprite.area = sprite_area;
} else { } else {
empty_icon.icon.data.indirected_sprite.area = 1; empty_icon.icon.data.indirected_sprite.area = (osspriteop_area *) 1;
} }
empty_icon.icon.data.indirected_sprite.size = 12; empty_icon.icon.data.indirected_sprite.size = 12;
if (xwimp_create_icon(&empty_icon, &icon_handle)) { if (xwimp_create_icon(&empty_icon, &icon_handle)) {
@ -310,41 +336,31 @@ void ro_toolbar_destroy(struct toolbar *toolbar) {
* \param sprite the requested sprite * \param sprite the requested sprite
* \param icon the icon number * \param icon the icon number
*/ */
static struct toolbar_icon *ro_toolbar_create_icon(osspriteop_area *sprite_area, char *sprite, unsigned int icon) { struct toolbar_icon *ro_toolbar_initialise_icon(osspriteop_area *sprite_area,
const char *sprite, unsigned int icon) {
struct toolbar_icon *current_icon; struct toolbar_icon *current_icon;
int i;
int sprite_name_size = 0;
os_coord dimensions; os_coord dimensions;
char name[16]; char name[16];
osbool mask; osbool mask;
os_mode mode; os_mode mode;
unsigned int validation_length; os_error *error;
/* Check if the sprite exists strcpy(name, sprite);
*/
for (i = 1; i <= sprite_area->sprite_count; i++) {
if (!xosspriteop_return_name(osspriteop_USER_AREA,
sprite_area, name, 16, i, &sprite_name_size)) {
name[sprite_name_size] = '\0';
if (strncmp(name, sprite, sprite_name_size + 1) == 0) {
/* Yes, a while loop would be better...
*/
goto ro_toolbar_create_icon_found;
}
}
}
/* No icon found
*/
return NULL;
ro_toolbar_create_icon_found:
/* Get the sprite details /* Get the sprite details
*/ */
xosspriteop_read_sprite_info(osspriteop_USER_AREA, error = xosspriteop_read_sprite_info(osspriteop_USER_AREA,
sprite_area, (osspriteop_id)name, sprite_area, (osspriteop_id) name,
&dimensions.x, &dimensions.y, &mask, &mode); &dimensions.x, &dimensions.y, &mask, &mode);
if (error && error->errnum == error_SPRITE_OP_DOESNT_EXIST) {
/** \todo inform user */
return NULL;
} else if (error) {
LOG(("xosspriteop_read_sprite_info: 0x%x: %s",
error->errnum, error->errmess));
warn_user(error->errmess);
return NULL;
}
/* Create an icon /* Create an icon
*/ */
@ -355,12 +371,6 @@ ro_toolbar_create_icon_found:
there is a pushed variant as RISC OS happily ignores it if it doesn't there is a pushed variant as RISC OS happily ignores it if it doesn't
exist. exist.
*/ */
validation_length = sprite_name_size * 2 + 8;
current_icon->validation = malloc(validation_length);
if (!current_icon->validation) {
free(current_icon);
return NULL;
}
sprintf(current_icon->validation, "R5;S%s,p%s", name, name); sprintf(current_icon->validation, "R5;S%s,p%s", name, name);
/* We want eig factors rather than pixels /* We want eig factors rather than pixels
@ -407,7 +417,6 @@ static struct toolbar_icon *ro_toolbar_create_separator(void) {
* \param icon the icon to destroy * \param icon the icon to destroy
*/ */
static void ro_toolbar_destroy_icon(struct toolbar_icon *icon) { static void ro_toolbar_destroy_icon(struct toolbar_icon *icon) {
if (!icon->icon_number >= 0) free(icon->validation);
free(icon); free(icon);
} }

View File

@ -15,29 +15,7 @@
#include "oslib/wimp.h" #include "oslib/wimp.h"
struct toolbar_icon { struct toolbar_icon;
/* The desired WIMP icon number (-1 for separator)
*/
int icon_number;
/* Set to non-zero to display the icon
*/
unsigned int available;
/* Icon dimensions (OS units)
*/
unsigned int width;
unsigned int height;
/* Icon validation, or NULL if this icon is unavailable
*/
unsigned char* validation;
/* The next icon (linked list)
*/
struct toolbar_icon *next_icon; // Next toolbar icon
};
struct toolbar { struct toolbar {
@ -51,7 +29,7 @@ struct toolbar {
int status_old_width; // Old status width int status_old_width; // Old status width
int width; // Toolbar width on last reformat int width; // Toolbar width on last reformat
unsigned int height; // Toolbar height on last reformat unsigned int height; // Toolbar height on last reformat
/* General options /* General options
*/ */
unsigned int throbber_width; // Throbber width (0 = unavaiable) unsigned int throbber_width; // Throbber width (0 = unavaiable)
@ -61,11 +39,11 @@ struct toolbar {
unsigned int url_bar; // Show URL bar? unsigned int url_bar; // Show URL bar?
unsigned int throbber; // Show Throbber? unsigned int throbber; // Show Throbber?
unsigned int status_width; // Width of status window unsigned int status_width; // Width of status window
/* The first toolbar icon /* The first toolbar icon
*/ */
struct toolbar_icon *icon; struct toolbar_icon *icon;
/* Window handles /* Window handles
*/ */
wimp_w toolbar_handle; wimp_w toolbar_handle;

View File

@ -775,6 +775,15 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar)
gui_window_redraw_window(g); gui_window_redraw_window(g);
return true; return true;
case wimp_KEY_F2:
if (!g->data.browser.toolbar)
return false;
ro_gui_set_icon_string(g->data.browser.toolbar->toolbar_handle,
ICON_TOOLBAR_URL, "www.");
xwimp_set_caret_position(g->data.browser.toolbar->toolbar_handle,
ICON_TOOLBAR_URL, 0, 0, -1, 4);
return true;
case wimp_KEY_CONTROL + wimp_KEY_F2: /* Close window. */ case wimp_KEY_CONTROL + wimp_KEY_F2: /* Close window. */
browser_window_destroy(g->data.browser.bw browser_window_destroy(g->data.browser.bw
#ifdef WITH_FRAMES #ifdef WITH_FRAMES