2003-11-15 03:26:42 +03:00
|
|
|
/*
|
2006-03-25 23:30:35 +03:00
|
|
|
* Copyright 2006 James Bursa <bursa@users.sourceforge.net>
|
2005-06-23 21:24:23 +04:00
|
|
|
* Copyright 2005 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-02-25 18:12:58 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
2006-03-25 23:30:35 +03:00
|
|
|
* Browser history window (RISC OS implementation).
|
|
|
|
*
|
|
|
|
* There is only one history window, not one per browser window.
|
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>
|
2003-11-15 03:26:42 +03:00
|
|
|
#include "oslib/wimp.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/history_core.h"
|
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "riscos/dialog.h"
|
|
|
|
#include "riscos/options.h"
|
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
2009-03-28 04:09:03 +03:00
|
|
|
#include "riscos/wimputils.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
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;
|
2006-03-25 23:30:35 +03:00
|
|
|
/* Last position of mouse in window. */
|
|
|
|
static int mouse_x = 0;
|
|
|
|
/* Last position of mouse in window. */
|
|
|
|
static int mouse_y = 0;
|
2003-11-15 03:26:42 +03:00
|
|
|
wimp_w history_window;
|
2006-03-25 23:30:35 +03:00
|
|
|
|
2005-12-31 07:40:49 +03:00
|
|
|
static void ro_gui_history_redraw(wimp_draw *redraw);
|
|
|
|
static bool ro_gui_history_click(wimp_pointer *pointer);
|
2003-11-15 03:26:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create history window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_init(void)
|
|
|
|
{
|
|
|
|
history_window = ro_gui_dialog_create("history");
|
2005-12-31 07:40:49 +03:00
|
|
|
ro_gui_wimp_event_register_redraw_window(history_window,
|
|
|
|
ro_gui_history_redraw);
|
|
|
|
ro_gui_wimp_event_register_mouse_click(history_window,
|
|
|
|
ro_gui_history_click);
|
|
|
|
ro_gui_wimp_event_set_help_prefix(history_window, "HelpHistory");
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2004-02-25 18:12:58 +03:00
|
|
|
* Open history window.
|
2005-02-07 17:28:43 +03:00
|
|
|
*
|
2006-03-25 23:30:35 +03:00
|
|
|
* \param bw browser window to open history for
|
|
|
|
* \param history history to open
|
|
|
|
* \param at_pointer open the window at the pointer
|
2003-11-15 03:26:42 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_open(struct browser_window *bw,
|
2006-03-25 23:30:35 +03:00
|
|
|
struct history *history, bool at_pointer)
|
2003-11-15 03:26:42 +03:00
|
|
|
{
|
2004-02-26 20:26:01 +03:00
|
|
|
int width, height;
|
2003-11-15 03:26:42 +03:00
|
|
|
os_box box = {0, 0, 0, 0};
|
2004-02-26 20:26:01 +03:00
|
|
|
wimp_window_state state;
|
2006-03-25 23:30:35 +03:00
|
|
|
os_error *error;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2006-07-13 16:46:02 +04:00
|
|
|
assert(history);
|
2003-11-15 03:26:42 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
history_current = history;
|
2006-03-25 23:30:35 +03:00
|
|
|
history_bw = bw;
|
2003-11-15 03:26:42 +03:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
history_size(history, &width, &height);
|
|
|
|
width *= 2;
|
|
|
|
height *= 2;
|
2004-02-26 20:26:01 +03:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
/* set extent */
|
2004-02-26 20:26:01 +03:00
|
|
|
box.x1 = width;
|
|
|
|
box.y0 = -height;
|
2006-03-25 23:30:35 +03:00
|
|
|
error = xwimp_set_extent(history_window, &box);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_set_extent: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open full size */
|
2004-02-26 20:26:01 +03:00
|
|
|
state.w = history_window;
|
2006-03-25 23:30:35 +03:00
|
|
|
error = xwimp_get_window_state(&state);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_window_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
2005-02-07 17:28:43 +03:00
|
|
|
state.visible.x0 = 0;
|
|
|
|
state.visible.y0 = 0;
|
|
|
|
state.visible.x1 = width;
|
|
|
|
state.visible.y1 = height;
|
|
|
|
state.next = wimp_HIDDEN;
|
2009-03-28 04:09:03 +03:00
|
|
|
error = xwimp_open_window(PTR_WIMP_OPEN(&state));
|
2006-03-25 23:30:35 +03:00
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_open_window: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ro_gui_dialog_open_persistent(bw->window->window, history_window,
|
|
|
|
at_pointer);
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw history window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_history_redraw(wimp_draw *redraw)
|
|
|
|
{
|
|
|
|
osbool more;
|
2006-03-25 23:30:35 +03:00
|
|
|
os_error *error;
|
2011-06-30 19:48:07 +04:00
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
|
|
|
.plot = &ro_plotters
|
|
|
|
};
|
2003-11-15 03:26:42 +03:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
error = xwimp_redraw_window(redraw, &more);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_redraw_window: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
2006-03-25 23:30:35 +03:00
|
|
|
while (more) {
|
|
|
|
ro_plot_origin_x = redraw->box.x0 - redraw->xscroll;
|
|
|
|
ro_plot_origin_y = redraw->box.y1 - redraw->yscroll;
|
2011-06-30 19:48:07 +04:00
|
|
|
history_redraw(history_current, &ctx);
|
2006-03-25 23:30:35 +03:00
|
|
|
error = xwimp_get_rectangle(redraw, &more);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_rectangle: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
2004-04-08 21:30:26 +04:00
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
|
2004-04-13 01:46:08 +04:00
|
|
|
/**
|
|
|
|
* Handle mouse movements over the history window.
|
|
|
|
*/
|
2006-03-25 23:30:35 +03:00
|
|
|
|
2004-04-13 01:46:08 +04:00
|
|
|
void ro_gui_history_mouse_at(wimp_pointer *pointer)
|
|
|
|
{
|
2005-03-21 03:15:48 +03:00
|
|
|
int x, y;
|
2009-03-28 04:09:03 +03:00
|
|
|
int width;
|
2006-03-25 23:30:35 +03:00
|
|
|
const char *url;
|
2004-04-13 01:46:08 +04:00
|
|
|
wimp_window_state state;
|
|
|
|
wimp_icon_state ic;
|
|
|
|
os_box box = {0, 0, 0, 0};
|
2006-03-25 23:30:35 +03:00
|
|
|
os_error *error;
|
2006-11-27 18:35:18 +03:00
|
|
|
|
2005-03-21 03:15:48 +03:00
|
|
|
/* 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;
|
2004-04-13 01:46:08 +04:00
|
|
|
|
2005-03-21 03:15:48 +03:00
|
|
|
/* Update mouse position */
|
2004-04-13 01:46:08 +04:00
|
|
|
mouse_x = pointer->pos.x;
|
|
|
|
mouse_y = pointer->pos.y;
|
|
|
|
|
2005-03-21 03:15:48 +03:00
|
|
|
/* Find history tree entry under mouse */
|
2004-04-13 01:46:08 +04:00
|
|
|
state.w = history_window;
|
2006-03-25 23:30:35 +03:00
|
|
|
error = xwimp_get_window_state(&state);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_window_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
2004-04-13 01:46:08 +04:00
|
|
|
}
|
2003-11-15 03:26:42 +03:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / 2;
|
|
|
|
y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / 2;
|
|
|
|
url = history_position_url(history_current, x, y);
|
|
|
|
if (!url) {
|
|
|
|
/* not over a tree entry => close tooltip window. */
|
|
|
|
error = xwimp_close_window(dialog_tooltip);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_close_window: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
/* get width of string */
|
|
|
|
error = xwimptextop_string_width(url,
|
|
|
|
strlen(url) > 256 ? 256 : strlen(url),
|
2009-03-28 04:09:03 +03:00
|
|
|
&width);
|
2006-03-25 23:30:35 +03:00
|
|
|
if (error) {
|
|
|
|
LOG(("xwimptextop_string_width: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
2003-11-15 03:26:42 +03:00
|
|
|
}
|
|
|
|
|
2008-08-05 05:23:04 +04:00
|
|
|
ro_gui_set_icon_string(dialog_tooltip, 0, url, true);
|
2004-02-26 20:52:10 +03:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
/* resize icon appropriately */
|
|
|
|
ic.w = dialog_tooltip;
|
|
|
|
ic.i = 0;
|
|
|
|
error = xwimp_get_icon_state(&ic);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_icon_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
2004-02-26 20:52:10 +03:00
|
|
|
return;
|
2006-03-25 23:30:35 +03:00
|
|
|
}
|
|
|
|
error = xwimp_resize_icon(dialog_tooltip, 0,
|
|
|
|
ic.icon.extent.x0, ic.icon.extent.y0,
|
|
|
|
width + 16, ic.icon.extent.y1);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_resize_icon: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
2004-02-26 20:52:10 +03:00
|
|
|
return;
|
2006-03-25 23:30:35 +03:00
|
|
|
}
|
2004-06-27 02:31:34 +04:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
state.w = dialog_tooltip;
|
|
|
|
error = xwimp_get_window_state(&state);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_window_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
2004-06-27 02:31:34 +04:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
/* update window extent */
|
|
|
|
box.x1 = width + 16;
|
|
|
|
box.y0 = -36;
|
|
|
|
error = xwimp_set_extent(dialog_tooltip, &box);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_set_extent: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
2004-06-27 02:31:34 +04:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
/* set visible area */
|
|
|
|
state.visible.x0 = pointer->pos.x + 24;
|
|
|
|
state.visible.y0 = pointer->pos.y - 22 - 36;
|
|
|
|
state.visible.x1 = pointer->pos.x + 24 + width + 16;
|
|
|
|
state.visible.y1 = pointer->pos.y - 22;
|
|
|
|
state.next = wimp_TOP;
|
|
|
|
/* open window */
|
2009-03-28 04:09:03 +03:00
|
|
|
error = xwimp_open_window(PTR_WIMP_OPEN(&state));
|
2006-03-25 23:30:35 +03:00
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_open_window: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return;
|
|
|
|
}
|
2004-06-27 02:31:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2006-03-25 23:30:35 +03:00
|
|
|
* Handle mouse clicks in the history window.
|
2004-06-27 02:31:34 +04:00
|
|
|
*
|
2006-03-25 23:30:35 +03:00
|
|
|
* \return true if the event was handled, false to pass it on
|
2004-06-27 02:31:34 +04:00
|
|
|
*/
|
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
bool ro_gui_history_click(wimp_pointer *pointer)
|
2004-08-07 02:19:13 +04:00
|
|
|
{
|
2006-03-25 23:30:35 +03:00
|
|
|
int x, y;
|
|
|
|
wimp_window_state state;
|
|
|
|
os_error *error;
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
if (pointer->buttons != wimp_CLICK_SELECT &&
|
|
|
|
pointer->buttons != wimp_CLICK_ADJUST)
|
|
|
|
/* return if not select or adjust click */
|
|
|
|
return true;
|
|
|
|
|
|
|
|
state.w = history_window;
|
|
|
|
error = xwimp_get_window_state(&state);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_get_window_state: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
return true;
|
2004-08-07 02:19:13 +04:00
|
|
|
}
|
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / 2;
|
|
|
|
y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / 2;
|
|
|
|
history_click(history_bw, history_current, x, y,
|
|
|
|
pointer->buttons == wimp_CLICK_ADJUST);
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2006-03-25 23:30:35 +03:00
|
|
|
return true;
|
2004-08-07 02:19:13 +04:00
|
|
|
}
|