2003-11-15 03:26:42 +03:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
2004-02-25 18:12:58 +03:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Browser history tree and window (implementation).
|
2003-11-15 03:26:42 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
2004-02-25 18:12:58 +03:00
|
|
|
#include <string.h>
|
2004-04-08 21:30:26 +04:00
|
|
|
#include <swis.h>
|
2003-12-27 03:11:57 +03:00
|
|
|
#include "oslib/colourtrans.h"
|
2003-11-15 03:26:42 +03:00
|
|
|
#include "oslib/font.h"
|
|
|
|
#include "oslib/wimp.h"
|
2004-04-08 21:30:26 +04:00
|
|
|
#include "netsurf/riscos/options.h"
|
2003-11-15 03:26:42 +03:00
|
|
|
#include "netsurf/riscos/gui.h"
|
2004-02-25 18:12:58 +03:00
|
|
|
#include "netsurf/riscos/thumbnail.h"
|
2004-04-08 21:30:26 +04:00
|
|
|
#include "netsurf/riscos/tinct.h"
|
2004-05-05 20:33:15 +04:00
|
|
|
#include "netsurf/riscos/wimp.h"
|
2003-11-15 03:26:42 +03:00
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
|
|
|
#define SIZE 10
|
2004-02-25 18:12:58 +03:00
|
|
|
#define WIDTH 200
|
|
|
|
#define HEIGHT 150
|
2003-11-15 03:26:42 +03:00
|
|
|
#define MARGIN 32
|
2004-02-25 18:12:58 +03:00
|
|
|
#define FULL_WIDTH (WIDTH + MARGIN + MARGIN)
|
|
|
|
#define FULL_HEIGHT (HEIGHT + MARGIN + MARGIN)
|
|
|
|
#define SPRITE_SIZE (16 + 44 + ((WIDTH / 2 + 3) & ~3) * HEIGHT / 2)
|
2003-11-15 03:26:42 +03:00
|
|
|
|
|
|
|
/** A node in the history tree. */
|
|
|
|
struct history_entry {
|
2004-02-25 18:12:58 +03:00
|
|
|
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. */
|
2003-11-15 03:26:42 +03:00
|
|
|
int x, y, width;
|
2004-02-25 18:12:58 +03:00
|
|
|
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;
|
2003-11-15 03:26:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct browser_window *history_bw;
|
2004-02-26 20:26:01 +03:00
|
|
|
static struct history *history_current = 0;
|
2004-04-13 01:46:08 +04:00
|
|
|
/* Position of mouse in window */
|
|
|
|
static int mouse_x = 0, mouse_y = 0;
|
2003-11-15 03:26:42 +03:00
|
|
|
wimp_w history_window;
|
|
|
|
font_f history_font;
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
static void history_free_entry(struct history_entry *entry);
|
2003-11-15 03:26:42 +03:00
|
|
|
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,
|
|
|
|
int x, int y);
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* 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) {
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("NoMemory", 0);
|
2004-02-25 18:12:58 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
history->start = 0;
|
|
|
|
history->current = 0;
|
|
|
|
|
|
|
|
return history;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-15 03:26:42 +03:00
|
|
|
/**
|
|
|
|
* Insert a url into the history tree.
|
|
|
|
*
|
2004-02-25 18:12:58 +03:00
|
|
|
* \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.
|
2003-11-15 03:26:42 +03:00
|
|
|
*/
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
void history_add(struct history *history, struct content *content)
|
2003-11-15 03:26:42 +03:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
struct history_entry *entry;
|
|
|
|
char *url;
|
|
|
|
char *title;
|
2003-11-15 03:26:42 +03:00
|
|
|
char *split;
|
|
|
|
int width;
|
2004-02-25 18:12:58 +03:00
|
|
|
osspriteop_area *area;
|
2004-04-11 00:04:11 +04:00
|
|
|
// os_error *error;
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
if (!history)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* allocate space */
|
|
|
|
entry = malloc(sizeof *entry);
|
|
|
|
url = strdup(content->url);
|
|
|
|
title = strdup(content->title ? content->title : url);
|
|
|
|
if (!entry || !url || !title) {
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("NoMemory", 0);
|
2004-02-25 18:12:58 +03:00
|
|
|
free(entry);
|
|
|
|
free(url);
|
|
|
|
free(title);
|
|
|
|
return;
|
|
|
|
}
|
2003-11-15 03:26:42 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/* truncate title to available width */
|
2003-11-15 03:26:42 +03:00
|
|
|
font_scan_string(history_font, title, font_GIVEN_FONT | font_KERN,
|
2004-02-25 18:12:58 +03:00
|
|
|
WIDTH * 400, 0x7fffffff,
|
2003-11-15 03:26:42 +03:00
|
|
|
0, 0, 0, &split, &width, 0, 0);
|
2004-02-25 18:12:58 +03:00
|
|
|
if (title[split - title]) {
|
|
|
|
title[split - title - 2] = 0x8c; /* ellipsis */
|
|
|
|
title[split - title - 1] = 0;
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
entry->url = url;
|
|
|
|
entry->title = title;
|
|
|
|
entry->back = history->current;
|
2003-11-15 03:26:42 +03:00
|
|
|
entry->next = 0;
|
2004-02-25 18:12:58 +03:00
|
|
|
entry->forward = entry->forward_pref = entry->forward_last = 0;
|
2003-11-15 03:26:42 +03:00
|
|
|
entry->children = 0;
|
|
|
|
entry->width = width / 400;
|
2004-02-25 18:12:58 +03:00
|
|
|
entry->sprite_area = 0;
|
|
|
|
if (history->current) {
|
|
|
|
if (history->current->forward_last)
|
|
|
|
history->current->forward_last->next = entry;
|
2003-11-15 03:26:42 +03:00
|
|
|
else
|
2004-02-25 18:12:58 +03:00
|
|
|
history->current->forward = entry;
|
|
|
|
history->current->forward_pref = entry;
|
|
|
|
history->current->forward_last = entry;
|
|
|
|
history->current->children++;
|
2003-11-15 03:26:42 +03:00
|
|
|
} else {
|
2004-02-25 18:12:58 +03:00
|
|
|
history->start = entry;
|
|
|
|
}
|
|
|
|
history->current = entry;
|
|
|
|
|
2004-04-11 00:04:11 +04:00
|
|
|
/* area = malloc(SPRITE_SIZE);
|
2004-02-25 18:12:58 +03:00
|
|
|
if (!area) {
|
|
|
|
LOG(("malloc failed"));
|
|
|
|
return;
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2004-04-11 00:04:11 +04:00
|
|
|
*/
|
|
|
|
area = thumbnail_initialise(WIDTH / 2, HEIGHT / 2, (os_mode)0x301680b5);
|
2004-04-13 01:46:08 +04:00
|
|
|
if (!area) {
|
2004-04-11 00:04:11 +04:00
|
|
|
LOG(("Thumbnail initialisation failed."));
|
|
|
|
return;
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
thumbnail_create(content, area,
|
2004-04-08 21:30:26 +04:00
|
|
|
(osspriteop_header *) (area + 1),
|
2004-02-25 18:12:58 +03:00
|
|
|
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 *)
|
2004-04-08 21:30:26 +04:00
|
|
|
(history->current->sprite_area + 1),
|
2004-02-25 18:12:58 +03:00
|
|
|
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;
|
2004-02-26 20:26:01 +03:00
|
|
|
if (history_current == history) {
|
|
|
|
wimp_close_window(history_window);
|
|
|
|
history_current = 0;
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
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);
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create history window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_init(void)
|
|
|
|
{
|
|
|
|
history_window = ro_gui_dialog_create("history");
|
2004-02-26 20:26:01 +03:00
|
|
|
history_font = font_find_font("Homerton.Medium", 112, 128, 0, 0, 0, 0);
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free history window resources.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_quit(void)
|
|
|
|
{
|
|
|
|
font_lose_font(history_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2004-02-25 18:12:58 +03:00
|
|
|
* Open history window.
|
2003-11-15 03:26:42 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_open(struct browser_window *bw,
|
2004-02-25 18:12:58 +03:00
|
|
|
struct history *history, int wx, int wy)
|
2003-11-15 03:26:42 +03:00
|
|
|
{
|
|
|
|
bool done = false;
|
2003-12-27 03:11:57 +03:00
|
|
|
unsigned int i, j, max_y = 0;
|
|
|
|
int x;
|
2004-02-26 20:26:01 +03:00
|
|
|
int width, height;
|
2003-11-15 03:26:42 +03:00
|
|
|
struct history_entry *row[SIZE], *row2[SIZE];
|
|
|
|
struct history_entry *he;
|
|
|
|
os_box box = {0, 0, 0, 0};
|
2004-02-26 20:26:01 +03:00
|
|
|
wimp_window_state state;
|
2003-11-15 03:26:42 +03:00
|
|
|
|
2004-02-25 18:59:01 +03:00
|
|
|
if (!history || !history->start)
|
|
|
|
return;
|
|
|
|
|
2003-11-15 03:26:42 +03:00
|
|
|
history_bw = bw;
|
2004-02-25 18:12:58 +03:00
|
|
|
history_current = history;
|
2003-11-15 03:26:42 +03:00
|
|
|
|
|
|
|
/* calculate layout */
|
|
|
|
for (i = 0; i != SIZE; i++)
|
|
|
|
row[i] = row2[i] = 0;
|
2004-02-25 18:12:58 +03:00
|
|
|
row[0] = history->start;
|
|
|
|
history->start->x = 0;
|
|
|
|
history->start->y = 0;
|
2003-11-15 03:26:42 +03:00
|
|
|
for (x = 1; !done; x++) {
|
|
|
|
for (i = 0; i != SIZE; i++) {
|
|
|
|
if (row[i]) {
|
|
|
|
for (j = i; j != SIZE && row2[j]; j++)
|
|
|
|
;
|
|
|
|
if (j == SIZE) {
|
|
|
|
if (row[i]->forward)
|
|
|
|
row[i]->forward->x = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (he = row[i]->forward; he; he = he->next) {
|
|
|
|
row2[j++] = he;
|
|
|
|
if (j == SIZE) {
|
|
|
|
if (he->next)
|
|
|
|
he->next->x = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (j == SIZE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done = true;
|
|
|
|
for (i = 0; i != SIZE; i++) {
|
|
|
|
row[i] = row2[i];
|
|
|
|
if (row[i]) {
|
|
|
|
row[i]->x = x;
|
|
|
|
row[i]->y = i;
|
|
|
|
if (max_y < i)
|
|
|
|
max_y = i;
|
|
|
|
done = false;
|
|
|
|
}
|
|
|
|
row2[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-26 20:26:01 +03:00
|
|
|
width = FULL_WIDTH * (x - 1);
|
|
|
|
height = FULL_HEIGHT * (max_y + 1);
|
|
|
|
|
|
|
|
box.x1 = width;
|
|
|
|
box.y0 = -height;
|
2003-11-15 03:26:42 +03:00
|
|
|
wimp_set_extent(history_window, &box);
|
2004-02-26 20:26:01 +03:00
|
|
|
state.w = history_window;
|
|
|
|
wimp_get_window_state(&state);
|
|
|
|
state.visible.x0 = wx - width / 2;
|
|
|
|
state.visible.y0 = wy - height / 2;
|
|
|
|
state.visible.x1 = wx + width / 2;
|
|
|
|
state.visible.y1 = wy + height / 2;
|
2004-02-26 20:52:10 +03:00
|
|
|
state.next = wimp_TOP;
|
2004-02-26 20:26:01 +03:00
|
|
|
wimp_open_window((wimp_open *) &state);
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw history window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_redraw(wimp_draw *redraw)
|
|
|
|
{
|
|
|
|
osbool more;
|
|
|
|
|
|
|
|
more = wimp_redraw_window(redraw);
|
|
|
|
|
|
|
|
while (more) {
|
2004-02-25 18:12:58 +03:00
|
|
|
ro_gui_history_redraw_tree(history_current->start,
|
2003-11-15 03:26:42 +03:00
|
|
|
redraw->box.x0 - redraw->xscroll,
|
|
|
|
redraw->box.y1 - redraw->yscroll);
|
|
|
|
more = wimp_get_rectangle(redraw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw history tree recursively.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_redraw_tree(struct history_entry *he,
|
|
|
|
int x0, int y0)
|
|
|
|
{
|
|
|
|
struct history_entry *c;
|
|
|
|
|
2004-02-26 20:26:01 +03:00
|
|
|
/* 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 == history_current->current)
|
|
|
|
colourtrans_set_gcol(os_COLOUR_RED, 0, os_ACTION_OVERWRITE, 0);
|
|
|
|
else
|
|
|
|
colourtrans_set_gcol(os_COLOUR_MID_DARK_GREY, 0,
|
|
|
|
os_ACTION_OVERWRITE, 0);
|
|
|
|
|
|
|
|
os_plot(os_MOVE_TO, x0 + he->x * FULL_WIDTH + MARGIN - 1,
|
2004-02-25 18:12:58 +03:00
|
|
|
y0 - he->y * FULL_HEIGHT - MARGIN);
|
2004-02-26 20:26:01 +03:00
|
|
|
os_plot(os_PLOT_SOLID | os_PLOT_BY, WIDTH + 1, 0);
|
|
|
|
os_plot(os_PLOT_SOLID | os_PLOT_BY, 0, -HEIGHT - 1);
|
|
|
|
os_plot(os_PLOT_SOLID | os_PLOT_BY, -WIDTH - 1, 0);
|
|
|
|
os_plot(os_PLOT_SOLID | os_PLOT_BY, 0, HEIGHT + 1);
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
if (he->sprite_area) {
|
|
|
|
osspriteop_area *area = he->sprite_area;
|
2004-04-08 21:30:26 +04:00
|
|
|
osspriteop_header *header = (osspriteop_header *)(area + 1);
|
2004-02-25 18:12:58 +03:00
|
|
|
osspriteop_trans_tab *table;
|
2004-04-08 21:30:26 +04:00
|
|
|
|
|
|
|
/* Because we're supporting people with OS3.1 we need to check if the
|
|
|
|
sprite we have is a legacy 256 colour one
|
|
|
|
*/
|
|
|
|
if (header->mode == (os_mode)0x301680b5) {
|
2004-04-11 03:12:28 +04:00
|
|
|
|
2004-04-08 21:30:26 +04:00
|
|
|
/* We plot with no mask and no scaling as any EIG factors are
|
|
|
|
handled internally by Tinct
|
|
|
|
*/
|
|
|
|
_swix(Tinct_Plot, _IN(2) | _IN(3) | _IN(4) | _IN(7),
|
|
|
|
(char *)(header),
|
2004-02-25 18:12:58 +03:00
|
|
|
x0 + he->x * FULL_WIDTH + MARGIN,
|
|
|
|
y0 - he->y * FULL_HEIGHT - FULL_HEIGHT + MARGIN,
|
2004-06-10 00:05:14 +04:00
|
|
|
(option_filter_sprites?tinct_BILINEAR_FILTER:0) | (option_dither_sprites?tinct_DITHER:0));
|
2004-04-08 21:30:26 +04:00
|
|
|
} else {
|
|
|
|
unsigned int size;
|
|
|
|
os_factors factors;
|
|
|
|
|
|
|
|
xcolourtrans_generate_table_for_sprite(
|
|
|
|
area, (osspriteop_id)header,
|
|
|
|
colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE,
|
|
|
|
0, colourtrans_GIVEN_SPRITE, 0, 0, &size);
|
2004-04-11 00:04:11 +04:00
|
|
|
LOG(("Table size of %i", size));
|
2004-04-08 21:30:26 +04:00
|
|
|
table = xcalloc(size, 1);
|
|
|
|
xcolourtrans_generate_table_for_sprite(
|
|
|
|
area, (osspriteop_id)header,
|
|
|
|
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, (osspriteop_id)header,
|
|
|
|
x0 + he->x * FULL_WIDTH + MARGIN,
|
|
|
|
y0 - he->y * FULL_HEIGHT - FULL_HEIGHT + MARGIN,
|
|
|
|
osspriteop_USE_MASK | osspriteop_USE_PALETTE, &factors, table);
|
|
|
|
|
|
|
|
xfree(table);
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2003-11-15 03:26:42 +03:00
|
|
|
|
2004-04-11 03:12:28 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
if (he == history_current->current)
|
2003-11-15 03:26:42 +03:00
|
|
|
wimp_set_font_colours(wimp_COLOUR_WHITE, wimp_COLOUR_RED);
|
2003-12-27 03:11:57 +03:00
|
|
|
else
|
2003-11-15 03:26:42 +03:00
|
|
|
wimp_set_font_colours(wimp_COLOUR_WHITE, wimp_COLOUR_BLACK);
|
|
|
|
|
|
|
|
font_paint(history_font, he->title,
|
|
|
|
font_OS_UNITS | font_GIVEN_FONT | font_KERN,
|
2004-02-25 18:12:58 +03:00
|
|
|
x0 + he->x * FULL_WIDTH + (FULL_WIDTH - he->width) / 2,
|
2004-04-11 03:12:28 +04:00
|
|
|
y0 - he->y * FULL_HEIGHT - HEIGHT - MARGIN - 24,
|
2003-11-15 03:26:42 +03:00
|
|
|
0, 0, 0);
|
2004-04-11 03:12:28 +04:00
|
|
|
|
2004-02-26 20:26:01 +03:00
|
|
|
|
|
|
|
colourtrans_set_gcol(os_COLOUR_MID_DARK_GREY, 0,
|
|
|
|
os_ACTION_OVERWRITE, 0);
|
2003-11-15 03:26:42 +03:00
|
|
|
|
|
|
|
for (c = he->forward; c; c = c->next) {
|
|
|
|
if (c->x == -1)
|
|
|
|
continue;
|
2004-02-25 18:12:58 +03:00
|
|
|
os_plot(os_MOVE_TO, x0 + c->x * FULL_WIDTH - MARGIN,
|
|
|
|
y0 - he->y * FULL_HEIGHT - FULL_HEIGHT / 2);
|
2003-11-15 03:26:42 +03:00
|
|
|
os_plot(os_PLOT_SOLID | os_PLOT_TO,
|
2004-02-25 18:12:58 +03:00
|
|
|
x0 + c->x * FULL_WIDTH + MARGIN,
|
|
|
|
y0 - c->y * FULL_HEIGHT - FULL_HEIGHT / 2);
|
2003-11-15 03:26:42 +03:00
|
|
|
ro_gui_history_redraw_tree(c, x0, y0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 01:46:08 +04:00
|
|
|
/**
|
|
|
|
* Handle mouse movements over the history window.
|
|
|
|
*/
|
|
|
|
void ro_gui_history_mouse_at(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
long width;
|
|
|
|
struct history_entry *he;
|
|
|
|
wimp_window_state state;
|
|
|
|
wimp_icon_state ic;
|
|
|
|
os_box box = {0, 0, 0, 0};
|
|
|
|
|
|
|
|
/* If the mouse hasn't moved, or if we don't want tooltips, exit */
|
|
|
|
if ((mouse_x == pointer->pos.x && mouse_y == pointer->pos.y) ||
|
|
|
|
!option_history_tooltip)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Update mouse position */
|
|
|
|
mouse_x = pointer->pos.x;
|
|
|
|
mouse_y = pointer->pos.y;
|
|
|
|
|
|
|
|
/* Find history tree entry under mouse */
|
|
|
|
state.w = history_window;
|
|
|
|
wimp_get_window_state(&state);
|
|
|
|
|
|
|
|
x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / FULL_WIDTH;
|
|
|
|
y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / FULL_HEIGHT;
|
|
|
|
he = ro_gui_history_click_find(history_current->start, x, y);
|
|
|
|
if (he) {
|
|
|
|
/* get width of string */
|
2004-04-13 02:04:51 +04:00
|
|
|
xwimptextop_string_width(he->url,
|
|
|
|
strlen(he->url) > 256 ? 256 : strlen(he->url),
|
|
|
|
(int*)&width);
|
2004-04-13 01:46:08 +04:00
|
|
|
|
|
|
|
ro_gui_set_icon_string(dialog_tooltip, 0, he->url);
|
|
|
|
|
|
|
|
/* resize icon appropriately */
|
|
|
|
ic.w = dialog_tooltip;
|
|
|
|
ic.i = 0;
|
|
|
|
wimp_get_icon_state(&ic);
|
|
|
|
wimp_resize_icon(dialog_tooltip, 0,
|
|
|
|
ic.icon.extent.x0, ic.icon.extent.y0,
|
2004-04-13 02:04:51 +04:00
|
|
|
width + 16, ic.icon.extent.y1);
|
2004-04-13 01:46:08 +04:00
|
|
|
|
|
|
|
state.w = dialog_tooltip;
|
|
|
|
wimp_get_window_state(&state);
|
|
|
|
|
|
|
|
/* update window extent */
|
2004-04-13 02:04:51 +04:00
|
|
|
box.x1 = width + 16;
|
2004-04-13 01:46:08 +04:00
|
|
|
box.y0 = -36;
|
|
|
|
xwimp_set_extent(dialog_tooltip, &box);
|
|
|
|
|
|
|
|
/* set visible area */
|
|
|
|
state.visible.x0 = pointer->pos.x + 24;
|
|
|
|
state.visible.y0 = pointer->pos.y - 22 - 36;
|
2004-04-13 02:04:51 +04:00
|
|
|
state.visible.x1 = pointer->pos.x + 24 + width + 16;
|
2004-04-13 01:46:08 +04:00
|
|
|
state.visible.y1 = pointer->pos.y - 22;
|
|
|
|
state.next = wimp_TOP;
|
|
|
|
/* open window */
|
|
|
|
wimp_open_window((wimp_open *) &state);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* not over a tree entry => close tooltip window. */
|
|
|
|
wimp_close_window(dialog_tooltip);
|
|
|
|
}
|
|
|
|
}
|
2003-11-15 03:26:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle mouse clicks in the history window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_click(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
struct history_entry *he;
|
|
|
|
wimp_window_state state;
|
|
|
|
|
|
|
|
state.w = history_window;
|
|
|
|
wimp_get_window_state(&state);
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / FULL_WIDTH;
|
|
|
|
y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / FULL_HEIGHT;
|
2003-11-15 03:26:42 +03:00
|
|
|
LOG(("x = %i, y = %i", x, y));
|
2004-02-25 18:12:58 +03:00
|
|
|
he = ro_gui_history_click_find(history_current->start, x, y);
|
2003-11-15 03:26:42 +03:00
|
|
|
if (he) {
|
2004-02-25 18:12:58 +03:00
|
|
|
history_current->current = he;
|
2004-02-26 20:26:01 +03:00
|
|
|
wimp_close_window(history_window);
|
|
|
|
history_current = 0;
|
2004-02-25 18:12:58 +03:00
|
|
|
browser_window_go_post(history_bw, he->url, 0, 0, false);
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search for an entry with the specified coordinates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct history_entry * ro_gui_history_click_find(struct history_entry *he,
|
|
|
|
int x, int y)
|
|
|
|
{
|
|
|
|
struct history_entry *c, *d;
|
|
|
|
if (he->x == x && he->y == y)
|
|
|
|
return he;
|
|
|
|
for (c = he->forward; c; c = c->next) {
|
|
|
|
d = ro_gui_history_click_find(c, x, y);
|
|
|
|
if (d)
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-02-26 20:52:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Go back in the history.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param history history of the window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void history_back(struct browser_window *bw, struct history *history)
|
|
|
|
{
|
|
|
|
if (!history || !history->current->back)
|
|
|
|
return;
|
|
|
|
history->current = history->current->back;
|
|
|
|
browser_window_go_post(bw, history->current->url, 0, 0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go forward in the history.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param history history of the window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void history_forward(struct browser_window *bw, struct history *history)
|
|
|
|
{
|
|
|
|
if (!history || !history->current->forward_pref)
|
|
|
|
return;
|
|
|
|
history->current = history->current->forward_pref;
|
|
|
|
browser_window_go_post(bw, history->current->url, 0, 0, false);
|
|
|
|
}
|