summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2003-12-19 00:40:28 +0000
committerJames Bursa <james@netsurf-browser.org>2003-12-19 00:40:28 +0000
commit7ec54af3596e52891d8fe5fcc08d6cb8990ff038 (patch)
treec991c413c00f7ab99b107d2f1a497bff9b482a19 /riscos
parent101c358751ea7249db3540637ac0ebf48e324618 (diff)
downloadnetsurf-7ec54af3596e52891d8fe5fcc08d6cb8990ff038.tar.gz
netsurf-7ec54af3596e52891d8fe5fcc08d6cb8990ff038.tar.bz2
[project @ 2003-12-19 00:40:28 by bursa]
Fix Themes menu, optimize toolbar opening. svn path=/import/netsurf/; revision=431
Diffstat (limited to 'riscos')
-rw-r--r--riscos/dialog.c150
-rw-r--r--riscos/gui.h1
-rw-r--r--riscos/menus.c15
-rw-r--r--riscos/window.c62
4 files changed, 111 insertions, 117 deletions
diff --git a/riscos/dialog.c b/riscos/dialog.c
index a3022a7a5..22f01225c 100644
--- a/riscos/dialog.c
+++ b/riscos/dialog.c
@@ -8,6 +8,7 @@
*/
#include <assert.h>
+#include <stddef.h>
#include <string.h>
#include "oslib/colourtrans.h"
#include "oslib/osfile.h"
@@ -279,10 +280,11 @@ void ro_gui_dialog_click_config_th(wimp_pointer *pointer)
else
set_theme_choices(&choices.theme);
break;
+ case ICON_CONFIG_TH_NAME:
case ICON_CONFIG_TH_PICK:
ro_gui_build_theme_menu();
- ro_gui_create_menu(theme_menu, pointer->pos.x - 64,
- pointer->pos.y, NULL);
+ ro_gui_popup_menu(theme_menu, dialog_config_th,
+ ICON_CONFIG_TH_PICK);
break;
case ICON_CONFIG_TH_MANAGE:
os_cli("Filer_OpenDir " THEMES_DIR);
@@ -444,101 +446,75 @@ void get_theme_choices(struct theme_choices* newchoices)
}
-void ro_gui_destroy_theme_menu(void)
+/**
+ * Construct or update theme_menu by scanning THEMES_DIR.
+ */
+
+void ro_gui_build_theme_menu(void)
{
- int i = 0;
- LOG(("destroy?"));
+ unsigned int i;
+ static unsigned int entries = 0;
+ int context = 0;
+ int read_count;
+ osgbpb_INFO(100) info;
+
+ if (theme_menu) {
+ /* free entry text buffers */
+ for (i = 0; i != entries; i++)
+ free(theme_menu->entries[i].data.indirected_text.text);
+ } else {
+ theme_menu = xcalloc(1, wimp_SIZEOF_MENU(1));
+ theme_menu->title_data.indirected_text.text =
+ messages_get("Themes");
+ theme_menu->title_fg = wimp_COLOUR_BLACK;
+ theme_menu->title_bg = wimp_COLOUR_LIGHT_GREY;
+ theme_menu->work_fg = wimp_COLOUR_BLACK;
+ theme_menu->work_bg = wimp_COLOUR_WHITE;
+ theme_menu->width = 256;
+ theme_menu->height = 44;
+ theme_menu->gap = 0;
+ }
- if (theme_menu == NULL)
- return;
+ i = 0;
+ while (context != -1) {
+ context = osgbpb_dir_entries_info(THEMES_DIR,
+ (osgbpb_info_list *) &info, 1, context,
+ sizeof(info), 0, &read_count);
+ if (read_count == 0)
+ continue;
+ if (info.obj_type != fileswitch_IS_DIR)
+ continue;
+ if (!(file_exists(THEMES_DIR, info.name, "Templates", 0xfec) &&
+ file_exists(THEMES_DIR, info.name, "Sprites", 0xff9)))
+ continue;
+
+ theme_menu = xrealloc(theme_menu, wimp_SIZEOF_MENU(i + 1));
+
+ theme_menu->entries[i].menu_flags = 0;
+ if (strcmp(info.name, theme_choices.name) == 0)
+ theme_menu->entries[i].menu_flags |= wimp_MENU_TICKED;
+ theme_menu->entries[i].sub_menu = wimp_NO_SUB_MENU;
+ theme_menu->entries[i].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);
+ theme_menu->entries[i].data.indirected_text.text =
+ xstrdup(info.name);
+ theme_menu->entries[i].data.indirected_text.validation = -1;
+ theme_menu->entries[i].data.indirected_text.size =
+ strlen(info.name) + 1;
- LOG(("enumerating"));
- while ((theme_menu->entries[i].menu_flags & wimp_MENU_LAST) == 0)
- {
- xfree(theme_menu->entries[i].data.indirected_text.text);
- LOG(("freed"));
i++;
}
+ assert(i != 0);
+ entries = i;
- LOG(("freeing menu"));
- xfree(theme_menu);
- theme_menu = NULL;
- LOG(("destroyed"));
+ theme_menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED;
+ theme_menu->entries[i - 1].menu_flags |= wimp_MENU_LAST;
}
-void ro_gui_build_theme_menu(void)
-{
- wimp_menu* m;
- int num = 0;
- int i;
- char* name[256];
- char buffer[256];
- osgbpb_system_info* info;
- int context = 0, count = 1;
-
- LOG(("check for destroy"));
- if (theme_menu != NULL)
- ro_gui_destroy_theme_menu();
- LOG(("enumerate themes"));
- context = osgbpb_dir_entries_system_info(THEMES_DIR, buffer, 1, context, 256, 0, &count);
- while (context != -1)
- {
- LOG(("called"));
- info = (osgbpb_system_info*) buffer;
- if (info->obj_type == 2 /* directory */)
- {
- if (file_exists(THEMES_DIR, info->name, "Templates", 0xfec) &&
- file_exists(THEMES_DIR, info->name, "Sprites", 0xff9) &&
- file_exists(THEMES_DIR, info->name, "IconNames", 0xfff) &&
- file_exists(THEMES_DIR, info->name, "IconSizes", 0xfff))
- {
- LOG(("found"));
- name[num] = malloc(strlen(info->name) + 2);
- strcpy(name[num], info->name);
- num++;
- }
- }
- context = osgbpb_dir_entries_system_info(THEMES_DIR, buffer, 1, context, 256, 0, &count);
- }
- LOG(("mallocing"));
-
- m = malloc(sizeof(wimp_menu_base) + (num*2) * sizeof(wimp_menu_entry));
- strcpy(m->title_data.text, "Themes");
- m->title_fg = wimp_COLOUR_BLACK;
- m->title_bg = wimp_COLOUR_LIGHT_GREY;
- m->work_fg = wimp_COLOUR_BLACK;
- m->work_bg = wimp_COLOUR_WHITE;
- m->width = 256;
- m->height = 44;
- m->gap = 0;
-
- LOG(("building entries"));
- for (i = 0; i < num; i++)
- {
- if (i < num - 1)
- m->entries[i].menu_flags = 0;
- else
- {
- LOG(("last one"));
- m->entries[i].menu_flags = wimp_MENU_LAST;
- }
-
- if (strcmp(name[i], theme_choices.name) == 0)
- m->entries[i].menu_flags |= wimp_MENU_TICKED;
-
- m->entries[i].sub_menu = wimp_NO_SUB_MENU;
- m->entries[i].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));
- m->entries[i].data.indirected_text.text = name[i];
- m->entries[i].data.indirected_text.validation = -1;
- m->entries[i].data.indirected_text.size = strlen(name[i]) + 1;
- LOG(("entry %d", i));
- }
- LOG(("done"));
-
- theme_menu = m;
-}
void ro_gui_theme_menu_selection(char *theme)
{
diff --git a/riscos/gui.h b/riscos/gui.h
index 4ff275f01..ab99b5104 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -102,6 +102,7 @@ void ro_gui_view_source(struct content *content);
/* in menus.c */
void ro_gui_menus_init(void);
void ro_gui_create_menu(wimp_menu* menu, int x, int y, gui_window* g);
+void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i);
void ro_gui_menu_selection(wimp_selection* selection);
/* in dialog.c */
diff --git a/riscos/menus.c b/riscos/menus.c
index 0ac15431a..12dbd1cb5 100644
--- a/riscos/menus.c
+++ b/riscos/menus.c
@@ -144,6 +144,21 @@ void ro_gui_create_menu(wimp_menu *menu, int x, int y, gui_window *g)
/**
+ * Display a pop-up menu next to the specified icon.
+ */
+
+void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i)
+{
+ wimp_window_state state = { w };
+ wimp_icon_state icon_state = { w, i };
+ wimp_get_window_state(&state);
+ wimp_get_icon_state(&icon_state);
+ ro_gui_create_menu(menu, state.visible.x0 + icon_state.icon.extent.x1,
+ state.visible.y1 + icon_state.icon.extent.y1, 0);
+}
+
+
+/**
* Handle menu selection.
*/
diff --git a/riscos/window.c b/riscos/window.c
index 3fbee0859..8af876d99 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -31,8 +31,10 @@ gui_window *window_list = 0;
gui_window *gui_create_browser_window(struct browser_window *bw)
{
int screen_width, screen_height, win_width, win_height;
+ int toolbar_height = 0;
wimp_window window;
wimp_window_state state;
+ wimp_outline outline;
gui_window* g = (gui_window*) xcalloc(1, sizeof(gui_window));
g->type = GUI_BROWSER_WINDOW;
@@ -40,6 +42,9 @@ gui_window *gui_create_browser_window(struct browser_window *bw)
ro_gui_screen_size(&screen_width, &screen_height);
+ if (bw->flags & browser_TOOLBAR)
+ toolbar_height = ro_theme_toolbar_height();
+
win_width = screen_width * 3 / 4;
if (1600 < win_width)
win_width = 1600;
@@ -68,14 +73,7 @@ gui_window *gui_create_browser_window(struct browser_window *bw)
window.extent.x0 = 0;
window.extent.y0 = win_height;
window.extent.x1 = win_width;
- if ((bw->flags & browser_TOOLBAR) != 0)
- {
- window.extent.y1 = ro_theme_toolbar_height();
- }
- else
- {
- window.extent.y1 = 0;
- }
+ window.extent.y1 = toolbar_height;
window.title_flags = wimp_ICON_TEXT | wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED;
window.work_flags = wimp_BUTTON_CLICK_DRAG << wimp_ICON_BUTTON_TYPE_SHIFT;
window.sprite_area = wimpspriteop_AREA;
@@ -110,6 +108,31 @@ gui_window *gui_create_browser_window(struct browser_window *bw)
state.next = wimp_TOP;
ro_gui_window_open(g, (wimp_open*)&state);
+ outline.w = g->window;
+ wimp_get_window_outline(&outline);
+
+ state.w = g->data.browser.toolbar;
+ state.visible.x1 = outline.outline.x1 - 2;
+ state.visible.y0 = state.visible.y1 - toolbar_height;
+ state.xscroll = 0;
+ state.yscroll = 0;
+ state.next = wimp_TOP;
+
+ g->data.browser.toolbar_width = state.visible.x1 - state.visible.x0;
+ ro_theme_resize_toolbar(g->data.browser.toolbar,
+ g->data.browser.toolbar_width,
+ state.visible.y1 - state.visible.y0);
+
+ wimp_open_window_nested((wimp_open *) &state, g->window,
+ wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
+ << wimp_CHILD_LS_EDGE_SHIFT |
+ wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
+ << wimp_CHILD_BS_EDGE_SHIFT |
+ wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT
+ << wimp_CHILD_RS_EDGE_SHIFT |
+ wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT
+ << wimp_CHILD_TS_EDGE_SHIFT);
+
return g;
}
@@ -304,7 +327,6 @@ void ro_gui_window_open(gui_window *g, wimp_open *open)
int toolbar_height = 0;
struct content *content;
wimp_window_state state;
- wimp_outline outline;
if (g->type != GUI_BROWSER_WINDOW) {
wimp_open_window(open);
@@ -374,28 +396,8 @@ void ro_gui_window_open(gui_window *g, wimp_open *open)
if (!toolbar_height)
return;
- outline.w = g->window;
- wimp_get_window_outline(&outline);
-
state.w = g->data.browser.toolbar;
- state.visible.x0 = open->visible.x0;
- state.visible.x1 = outline.outline.x1 - 2;
- state.visible.y1 = open->visible.y1;
- state.visible.y0 = state.visible.y1 - toolbar_height;
- state.xscroll = 0;
- state.yscroll = 0;
- state.next = wimp_TOP;
-
- wimp_open_window_nested((wimp_open *) &state, g->window,
- 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_TOP_OR_RIGHT
- << wimp_CHILD_TS_EDGE_SHIFT);
-
+ wimp_get_window_state(&state);
if (state.visible.x1 - state.visible.x0 !=
g->data.browser.toolbar_width) {
g->data.browser.toolbar_width = state.visible.x1 -