summaryrefslogtreecommitdiff
path: root/riscos/history.c
diff options
context:
space:
mode:
Diffstat (limited to 'riscos/history.c')
-rw-r--r--riscos/history.c304
1 files changed, 235 insertions, 69 deletions
diff --git a/riscos/history.c b/riscos/history.c
index 49fbf956f..9166f04d3 100644
--- a/riscos/history.c
+++ b/riscos/history.c
@@ -2,41 +2,61 @@
* 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 2003 James Bursa <bursa@users.sourceforge.net>
+ * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
+ */
+
+/** \file
+ * Browser history tree and window (implementation).
*/
#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include "oslib/colourtrans.h"
#include "oslib/font.h"
#include "oslib/wimp.h"
-#include "netsurf/utils/config.h"
#include "netsurf/riscos/gui.h"
+#include "netsurf/riscos/thumbnail.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/utils.h"
#define SIZE 10
-#define WIDTH 300
-#define HEIGHT 100
+#define WIDTH 200
+#define HEIGHT 150
#define MARGIN 32
+#define FULL_WIDTH (WIDTH + MARGIN + MARGIN)
+#define FULL_HEIGHT (HEIGHT + MARGIN + MARGIN)
+#define SPRITE_SIZE (16 + 44 + ((WIDTH / 2 + 3) & ~3) * HEIGHT / 2)
/** A node in the history tree. */
struct history_entry {
- char *url; /**< Page URL. */
- char *title; /**< Page title. */
- struct history_entry *back;
- struct history_entry *forward, *forward_pref, *forward_last;
- struct history_entry *prev, *next;
- unsigned int children;
+ char *url; /**< Page URL. */
+ char *title; /**< Page title. */
+ struct history_entry *back; /**< Parent. */
+ struct history_entry *next; /**< Next sibling. */
+ struct history_entry *forward; /**< First child. */
+ struct history_entry *forward_pref; /**< Child in direction of
+ current entry. */
+ struct history_entry *forward_last; /**< Last child. */
+ unsigned int children; /**< Number of children. */
int x, y, width;
+ osspriteop_area *sprite_area; /**< Thumbnail sprite area, or 0. */
+};
+
+/** History tree for a window. */
+struct history {
+ /** First page in tree (page that window opened with). */
+ struct history_entry *start;
+ /** Current position in tree. */
+ struct history_entry *current;
};
static struct browser_window *history_bw;
-static struct history_entry *history_start;
-static struct history_entry *history_current;
+static struct history *history_current;
wimp_w history_window;
font_f history_font;
+static void history_free_entry(struct history_entry *entry);
static void ro_gui_history_redraw_tree(struct history_entry *he,
int x0, int y0);
static struct history_entry * ro_gui_history_click_find(struct history_entry *he,
@@ -44,46 +64,169 @@ static struct history_entry * ro_gui_history_click_find(struct history_entry *he
/**
+ * Create a new history tree for a window.
+ *
+ * \return pointer to an opaque history structure, 0 on failure.
+ */
+
+struct history *history_create(void)
+{
+ struct history *history;
+
+ history = malloc(sizeof *history);
+ if (!history) {
+ warn_user("NoMemory");
+ return 0;
+ }
+
+ history->start = 0;
+ history->current = 0;
+
+ return history;
+}
+
+
+/**
* Insert a url into the history tree.
*
- * Takes a copy of the url and title and inserts an entry into the tree forward
- * from current, returning the new entry. current may be 0 to start a new tree.
+ * \param history opaque history structure, as returned by history_create()
+ * \param content content to add to history
+ *
+ * The page is added after the current entry and becomes current.
*/
-struct history_entry * history_add(struct history_entry *current,
- char *url, char *title)
+void history_add(struct history *history, struct content *content)
{
- struct history_entry *entry = xcalloc(1, sizeof(*entry));
+ struct history_entry *entry;
+ char *url;
+ char *title;
char *split;
int width;
+ osspriteop_area *area;
+ os_error *error;
+
+ if (!history)
+ return;
+
+ /* allocate space */
+ entry = malloc(sizeof *entry);
+ url = strdup(content->url);
+ title = strdup(content->title ? content->title : url);
+ if (!entry || !url || !title) {
+ warn_user("NoMemory");
+ free(entry);
+ free(url);
+ free(title);
+ return;
+ }
+ /* truncate title to available width */
font_scan_string(history_font, title, font_GIVEN_FONT | font_KERN,
- (WIDTH - MARGIN - MARGIN) * 400, 0x7fffffff,
+ WIDTH * 400, 0x7fffffff,
0, 0, 0, &split, &width, 0, 0);
-
- entry->url = xstrdup(url);
- entry->title = xstrdup(title);
- if (entry->title[split - title]) {
- entry->title[split - title - 2] = 0x8c; /* ellipsis */
- entry->title[split - title - 1] = 0;
+ if (title[split - title]) {
+ title[split - title - 2] = 0x8c; /* ellipsis */
+ title[split - title - 1] = 0;
}
- entry->back = current;
- entry->forward = entry->forward_pref = entry->forward_last = 0;
+
+ entry->url = url;
+ entry->title = title;
+ entry->back = history->current;
entry->next = 0;
+ entry->forward = entry->forward_pref = entry->forward_last = 0;
entry->children = 0;
entry->width = width / 400;
- if (current) {
- entry->prev = current->forward_last;
- if (current->forward_last)
- current->forward_last->next = entry;
+ entry->sprite_area = 0;
+ if (history->current) {
+ if (history->current->forward_last)
+ history->current->forward_last->next = entry;
else
- current->forward = entry;
- current->forward_pref = current->forward_last = entry;
- current->children++;
+ history->current->forward = entry;
+ history->current->forward_pref = entry;
+ history->current->forward_last = entry;
+ history->current->children++;
} else {
- entry->prev = 0;
+ history->start = entry;
+ }
+ history->current = entry;
+
+ area = malloc(SPRITE_SIZE);
+ if (!area) {
+ LOG(("malloc failed"));
+ return;
}
- return entry;
+
+ area->size = SPRITE_SIZE;
+ area->sprite_count = 0;
+ area->first = 16;
+ area->used = 16;
+
+ error = xosspriteop_create_sprite(osspriteop_NAME,
+ area, "thumbnail", false,
+ WIDTH / 2, HEIGHT / 2, os_MODE8BPP90X90);
+ if (error) {
+ LOG(("0x%x: %s", error->errnum, error->errmess));
+ return;
+ }
+
+ thumbnail_create(content, area,
+ (osspriteop_header *) ((char *) area + 16),
+ WIDTH / 2, HEIGHT / 2);
+/* xosspriteop_save_sprite_file(osspriteop_NAME,
+ area, "thumbnail");*/
+
+ entry->sprite_area = area;
+}
+
+
+/**
+ * Update the thumbnail for the current entry.
+ *
+ * \param history opaque history structure, as returned by history_create()
+ * \param content content for current entry
+ */
+
+void history_update(struct history *history, struct content *content)
+{
+ if (!history || !history->current->sprite_area)
+ return;
+
+ thumbnail_create(content, history->current->sprite_area,
+ (osspriteop_header *)
+ ((char *) history->current->sprite_area + 16),
+ WIDTH / 2, HEIGHT / 2);
+}
+
+
+/**
+ * Free a history structure.
+ *
+ * \param history opaque history structure, as returned by history_create()
+ */
+
+void history_destroy(struct history *history)
+{
+ if (!history)
+ return;
+ history_free_entry(history->start);
+ free(history);
+}
+
+
+/**
+ * Free an entry in the tree recursively.
+ */
+
+void history_free_entry(struct history_entry *entry)
+{
+ if (!entry)
+ return;
+ history_free_entry(entry->forward);
+ history_free_entry(entry->next);
+ free(entry->url);
+ free(entry->title);
+ free(entry->sprite_area);
+ free(entry);
}
@@ -109,11 +252,11 @@ void ro_gui_history_quit(void)
/**
- * Open history window at a specified entry.
+ * Open history window.
*/
void ro_gui_history_open(struct browser_window *bw,
- struct history_entry *entry, int wx, int wy)
+ struct history *history, int wx, int wy)
{
bool done = false;
unsigned int i, j, max_y = 0;
@@ -123,18 +266,14 @@ void ro_gui_history_open(struct browser_window *bw,
os_box box = {0, 0, 0, 0};
history_bw = bw;
- history_current = entry;
- for (history_start = entry;
- history_start->back;
- history_start = history_start->back)
- ;
+ history_current = history;
/* calculate layout */
for (i = 0; i != SIZE; i++)
row[i] = row2[i] = 0;
- row[0] = history_start;
- history_start->x = 0;
- history_start->y = 0;
+ row[0] = history->start;
+ history->start->x = 0;
+ history->start->y = 0;
for (x = 1; !done; x++) {
for (i = 0; i != SIZE; i++) {
if (row[i]) {
@@ -171,8 +310,8 @@ void ro_gui_history_open(struct browser_window *bw,
}
}
- box.x1 = WIDTH * (x - 1);
- box.y0 = -(HEIGHT * (max_y + 1));
+ box.x1 = FULL_WIDTH * (x - 1);
+ box.y0 = -(FULL_HEIGHT * (max_y + 1));
wimp_set_extent(history_window, &box);
wimp_create_menu((wimp_menu *) history_window, wx, wy);
}
@@ -190,7 +329,7 @@ void ro_gui_history_redraw(wimp_draw *redraw)
colourtrans_set_gcol(os_COLOUR_WHITE, 0, os_ACTION_OVERWRITE, 0);
while (more) {
- ro_gui_history_redraw_tree(history_start,
+ ro_gui_history_redraw_tree(history_current->start,
redraw->box.x0 - redraw->xscroll,
redraw->box.y1 - redraw->yscroll);
more = wimp_get_rectangle(redraw);
@@ -207,30 +346,62 @@ void ro_gui_history_redraw_tree(struct history_entry *he,
{
struct history_entry *c;
- os_plot(os_MOVE_TO, x0 + he->x * WIDTH + MARGIN,
- y0 - he->y * HEIGHT - MARGIN);
- os_plot(os_PLOT_RECTANGLE | os_PLOT_BY, WIDTH - MARGIN - MARGIN,
- -(HEIGHT - MARGIN - MARGIN));
+ os_plot(os_MOVE_TO, x0 + he->x * FULL_WIDTH + MARGIN,
+ y0 - he->y * FULL_HEIGHT - MARGIN);
+ os_plot(os_PLOT_RECTANGLE | os_PLOT_BY, WIDTH, -HEIGHT);
+
+ if (he->sprite_area) {
+ unsigned int size;
+ osspriteop_area *area = he->sprite_area;
+ osspriteop_trans_tab *table;
+ os_factors factors;
+
+ xcolourtrans_generate_table_for_sprite(
+ area,
+ (char *) area + 16,
+ colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE,
+ 0, colourtrans_GIVEN_SPRITE, 0, 0, &size);
+ table = xcalloc(size, 1);
+ xcolourtrans_generate_table_for_sprite(
+ area,
+ (char *) area + 16,
+ colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE,
+ table, colourtrans_GIVEN_SPRITE, 0, 0, 0);
+
+ factors.xmul = 1;
+ factors.ymul = 1;
+ factors.xdiv = 1;
+ factors.ydiv = 1;
+
+ xosspriteop_put_sprite_scaled(osspriteop_PTR,
+ area,
+ (char *) area + 16,
+ x0 + he->x * FULL_WIDTH + MARGIN,
+ y0 - he->y * FULL_HEIGHT - FULL_HEIGHT + MARGIN,
+ osspriteop_USE_MASK | osspriteop_USE_PALETTE, &factors, table);
+
+ xfree(table);
+ }
- if (he == history_current)
+ if (he == history_current->current)
wimp_set_font_colours(wimp_COLOUR_WHITE, wimp_COLOUR_RED);
else
wimp_set_font_colours(wimp_COLOUR_WHITE, wimp_COLOUR_BLACK);
font_paint(history_font, he->title,
font_OS_UNITS | font_GIVEN_FONT | font_KERN,
- x0 + he->x * WIDTH + (WIDTH - he->width) / 2,
- y0 - he->y * HEIGHT - MARGIN - 24,
+ x0 + he->x * FULL_WIDTH + (FULL_WIDTH - he->width) / 2,
+ y0 - he->y * FULL_HEIGHT - MARGIN - 24,
0, 0, 0);
for (c = he->forward; c; c = c->next) {
if (c->x == -1)
continue;
- os_plot(os_MOVE_TO, x0 + c->x * WIDTH - MARGIN,
- y0 - he->y * HEIGHT - HEIGHT / 2);
+ os_plot(os_MOVE_TO, x0 + c->x * FULL_WIDTH - MARGIN,
+ y0 - he->y * FULL_HEIGHT - FULL_HEIGHT / 2);
os_plot(os_PLOT_SOLID | os_PLOT_TO,
- x0 + c->x * WIDTH + MARGIN,
- y0 - c->y * HEIGHT - HEIGHT / 2);
+ x0 + c->x * FULL_WIDTH + MARGIN,
+ y0 - c->y * FULL_HEIGHT - FULL_HEIGHT / 2);
ro_gui_history_redraw_tree(c, x0, y0);
}
}
@@ -249,19 +420,14 @@ void ro_gui_history_click(wimp_pointer *pointer)
state.w = history_window;
wimp_get_window_state(&state);
- x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / WIDTH;
- y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / HEIGHT;
+ x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / FULL_WIDTH;
+ y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / FULL_HEIGHT;
LOG(("x = %i, y = %i", x, y));
- he = ro_gui_history_click_find(history_start, x, y);
+ he = ro_gui_history_click_find(history_current->start, x, y);
if (he) {
- history_bw->history_entry = he;
+ history_current->current = he;
wimp_create_menu(wimp_CLOSE_MENU, 0, 0);
- browser_window_open_location_historical(history_bw,
- he->url
-#ifdef WITH_POST
- , 0, 0
-#endif
- );
+ browser_window_go_post(history_bw, he->url, 0, 0, false);
}
}