2009-03-07 23:52:08 +03:00
|
|
|
/*
|
2010-03-18 00:00:18 +03:00
|
|
|
* Copyright 2009, 2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2009-03-07 23:52:08 +03: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
2009-08-29 18:41:24 +04:00
|
|
|
* Browser history window (AmigaOS implementation).
|
2009-03-07 23:52:08 +03:00
|
|
|
*
|
|
|
|
* There is only one history window, not one per browser window.
|
|
|
|
*/
|
|
|
|
|
2015-01-20 23:51:52 +03:00
|
|
|
#include "amiga/os3support.h"
|
|
|
|
|
2009-03-07 23:52:08 +03:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <proto/intuition.h>
|
2009-03-08 15:52:44 +03:00
|
|
|
#include <proto/exec.h>
|
2009-03-08 19:24:52 +03:00
|
|
|
#include <proto/graphics.h>
|
2009-03-09 02:08:27 +03:00
|
|
|
#include <intuition/icclass.h>
|
|
|
|
#include <proto/utility.h>
|
2009-03-07 23:52:08 +03:00
|
|
|
#include <proto/window.h>
|
|
|
|
#include <proto/space.h>
|
|
|
|
#include <proto/layout.h>
|
|
|
|
#include <classes/window.h>
|
2009-03-08 15:52:44 +03:00
|
|
|
#include <gadgets/space.h>
|
2009-03-09 02:08:27 +03:00
|
|
|
#include <gadgets/scroller.h>
|
2009-03-07 23:52:08 +03:00
|
|
|
#include <reaction/reaction.h>
|
|
|
|
#include <reaction/reaction_macros.h>
|
|
|
|
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "desktop/browser_history.h"
|
2014-11-21 12:26:08 +03:00
|
|
|
#include "desktop/browser.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "desktop/gui_window.h"
|
|
|
|
#include "graphics/rpattr.h"
|
|
|
|
|
2015-01-26 03:05:01 +03:00
|
|
|
#include "amiga/libs.h"
|
2015-01-20 23:51:52 +03:00
|
|
|
#include "amiga/misc.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "amiga/object.h"
|
|
|
|
#include "amiga/gui.h"
|
|
|
|
#include "amiga/history_local.h"
|
|
|
|
|
2009-03-09 02:08:27 +03:00
|
|
|
void ami_history_update_extent(struct history_window *hw);
|
2015-02-24 22:51:51 +03:00
|
|
|
HOOKF(void, ami_history_scroller_hook, Object *, object, struct IntuiMessage *);
|
2009-03-09 02:08:27 +03:00
|
|
|
|
2009-03-07 23:52:08 +03:00
|
|
|
/**
|
2014-11-16 18:42:45 +03:00
|
|
|
* Redraw history window.
|
2009-03-07 23:52:08 +03:00
|
|
|
*/
|
|
|
|
|
2014-11-16 18:42:45 +03:00
|
|
|
static void ami_history_redraw(struct history_window *hw)
|
|
|
|
{
|
|
|
|
struct IBox *bbox;
|
|
|
|
ULONG xs,ys;
|
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
|
|
|
.background_images = true,
|
|
|
|
.plot = &amiplot
|
|
|
|
};
|
|
|
|
|
|
|
|
GetAttr(SCROLLER_Top,hw->objects[OID_HSCROLL],(ULONG *)&xs);
|
|
|
|
GetAttr(SCROLLER_Top,hw->objects[OID_VSCROLL],(ULONG *)&ys);
|
|
|
|
if(ami_gui_get_space_box(hw->objects[GID_BROWSER], &bbox) != NSERROR_OK) {
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user("NoMemory", "");
|
2014-11-16 18:42:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
glob = &hw->gg;
|
|
|
|
|
|
|
|
SetRPAttrs(glob->rp, RPTAG_APenColor, 0xffffffff, TAG_DONE);
|
|
|
|
RectFill(glob->rp, 0, 0, bbox->Width - 1, bbox->Height - 1);
|
|
|
|
|
|
|
|
browser_window_history_redraw_rectangle(hw->gw->bw, xs, ys,
|
|
|
|
bbox->Width + xs, bbox->Height + ys, 0, 0, &ctx);
|
|
|
|
|
|
|
|
glob = &browserglob;
|
|
|
|
|
|
|
|
ami_clearclipreg(&hw->gg);
|
|
|
|
ami_history_update_extent(hw);
|
|
|
|
|
|
|
|
BltBitMapRastPort(hw->gg.bm, 0, 0, hw->win->RPort,
|
|
|
|
bbox->Left, bbox->Top, bbox->Width, bbox->Height, 0x0C0);
|
|
|
|
|
|
|
|
ami_gui_free_space_box(bbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* exported interface documented in amiga/history_local.h */
|
2014-11-22 02:58:56 +03:00
|
|
|
void ami_history_open(struct gui_window *gw)
|
2009-03-07 23:52:08 +03:00
|
|
|
{
|
2014-11-22 02:58:56 +03:00
|
|
|
struct history *history;
|
2009-03-07 23:52:08 +03:00
|
|
|
int width, height;
|
|
|
|
|
2014-11-22 02:58:56 +03:00
|
|
|
if (gw->bw == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
history = browser_window_get_history(gw->bw);
|
|
|
|
if (history == NULL)
|
|
|
|
return;
|
2009-03-07 23:52:08 +03:00
|
|
|
|
2014-11-16 18:51:57 +03:00
|
|
|
if(!gw->hw)
|
2009-03-08 19:24:52 +03:00
|
|
|
{
|
2015-01-18 21:55:23 +03:00
|
|
|
gw->hw = ami_misc_allocvec_clear(sizeof(struct history_window), 0);
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2016-01-25 03:01:55 +03:00
|
|
|
ami_init_layers(&gw->hw->gg, scrn->Width, scrn->Height, false);
|
2009-08-29 18:41:24 +04:00
|
|
|
|
2014-11-16 18:51:57 +03:00
|
|
|
gw->hw->gw = gw;
|
2014-11-16 18:42:45 +03:00
|
|
|
browser_window_history_size(gw->bw, &width, &height);
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2014-11-16 18:51:57 +03:00
|
|
|
gw->hw->scrollerhook.h_Entry = (void *)ami_history_scroller_hook;
|
|
|
|
gw->hw->scrollerhook.h_Data = gw->hw;
|
2009-03-09 02:08:27 +03:00
|
|
|
|
2015-01-26 03:05:01 +03:00
|
|
|
gw->hw->objects[OID_MAIN] = WindowObj,
|
2014-11-16 19:40:41 +03:00
|
|
|
WA_ScreenTitle, ami_gui_get_screen_title(),
|
|
|
|
WA_Title, messages_get("History"),
|
2009-03-08 19:24:52 +03:00
|
|
|
WA_Activate, TRUE,
|
|
|
|
WA_DepthGadget, TRUE,
|
|
|
|
WA_DragBar, TRUE,
|
|
|
|
WA_CloseGadget, TRUE,
|
|
|
|
WA_SizeGadget, TRUE,
|
2013-03-20 12:22:03 +04:00
|
|
|
WA_PubScreen,scrn,
|
2009-03-08 19:24:52 +03:00
|
|
|
WA_InnerWidth,width,
|
2009-08-29 18:41:24 +04:00
|
|
|
WA_InnerHeight,height + 10,
|
2009-03-08 19:24:52 +03:00
|
|
|
WINDOW_SharedPort,sport,
|
2014-11-16 18:51:57 +03:00
|
|
|
WINDOW_UserData,gw->hw,
|
2009-03-08 19:24:52 +03:00
|
|
|
WINDOW_IconifyGadget, FALSE,
|
2010-03-18 00:00:18 +03:00
|
|
|
WINDOW_GadgetHelp, TRUE,
|
2009-03-08 19:24:52 +03:00
|
|
|
WINDOW_Position, WPOS_CENTERSCREEN,
|
2009-03-09 02:08:27 +03:00
|
|
|
WINDOW_HorizProp,1,
|
|
|
|
WINDOW_VertProp,1,
|
2014-11-16 18:51:57 +03:00
|
|
|
WINDOW_IDCMPHook,&gw->hw->scrollerhook,
|
2009-03-09 02:08:27 +03:00
|
|
|
WINDOW_IDCMPHookBits,IDCMP_IDCMPUPDATE,
|
|
|
|
// WA_ReportMouse,TRUE,
|
2009-03-08 19:24:52 +03:00
|
|
|
WA_IDCMP,IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE, // | IDCMP_MOUSEMOVE,
|
2015-01-26 03:05:01 +03:00
|
|
|
WINDOW_ParentGroup, gw->hw->objects[GID_MAIN] = LayoutVObj,
|
|
|
|
LAYOUT_AddChild, gw->hw->objects[GID_BROWSER] = SpaceObj,
|
2009-03-08 19:24:52 +03:00
|
|
|
GA_ID,GID_BROWSER,
|
|
|
|
// SPACE_MinWidth,width,
|
|
|
|
// SPACE_MinHeight,height,
|
|
|
|
SpaceEnd,
|
|
|
|
EndGroup,
|
|
|
|
EndWindow;
|
|
|
|
|
2014-11-16 18:51:57 +03:00
|
|
|
gw->hw->win = (struct Window *)RA_OpenWindow(gw->hw->objects[OID_MAIN]);
|
|
|
|
gw->hw->node = AddObject(window_list,AMINS_HISTORYWINDOW);
|
|
|
|
gw->hw->node->objstruct = gw->hw;
|
2009-03-09 02:08:27 +03:00
|
|
|
|
2014-11-16 18:51:57 +03:00
|
|
|
GetAttr(WINDOW_HorizObject,gw->hw->objects[OID_MAIN],(ULONG *)&gw->hw->objects[OID_HSCROLL]);
|
|
|
|
GetAttr(WINDOW_VertObject,gw->hw->objects[OID_MAIN],(ULONG *)&gw->hw->objects[OID_VSCROLL]);
|
2009-03-09 02:08:27 +03:00
|
|
|
|
2014-11-16 18:51:57 +03:00
|
|
|
RefreshSetGadgetAttrs((APTR)gw->hw->objects[OID_VSCROLL],gw->hw->win,NULL,
|
2009-03-09 02:08:27 +03:00
|
|
|
GA_ID,OID_VSCROLL,
|
|
|
|
SCROLLER_Top,0,
|
|
|
|
ICA_TARGET,ICTARGET_IDCMP,
|
|
|
|
TAG_DONE);
|
|
|
|
|
2014-11-16 18:51:57 +03:00
|
|
|
RefreshSetGadgetAttrs((APTR)gw->hw->objects[OID_HSCROLL],gw->hw->win,NULL,
|
2009-03-09 02:08:27 +03:00
|
|
|
GA_ID,OID_HSCROLL,
|
|
|
|
SCROLLER_Top,0,
|
|
|
|
ICA_TARGET,ICTARGET_IDCMP,
|
|
|
|
TAG_DONE);
|
2009-03-08 19:24:52 +03:00
|
|
|
}
|
|
|
|
|
2014-11-16 18:51:57 +03:00
|
|
|
ami_history_redraw(gw->hw);
|
2009-03-07 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle mouse clicks in the history window.
|
|
|
|
*
|
|
|
|
* \return true if the event was handled, false to pass it on
|
|
|
|
*/
|
|
|
|
|
2014-11-16 18:42:45 +03:00
|
|
|
static bool ami_history_click(struct history_window *hw, uint16 code)
|
2009-03-07 23:52:08 +03:00
|
|
|
{
|
|
|
|
int x, y;
|
2009-03-08 19:24:52 +03:00
|
|
|
struct IBox *bbox;
|
2016-01-15 22:58:24 +03:00
|
|
|
ULONG xs, ys;
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2014-11-15 17:39:54 +03:00
|
|
|
if(ami_gui_get_space_box(hw->objects[GID_BROWSER], &bbox) != NSERROR_OK) {
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user("NoMemory", "");
|
2014-11-15 17:39:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2009-03-09 02:08:27 +03:00
|
|
|
GetAttr(SCROLLER_Top,hw->objects[OID_HSCROLL],(ULONG *)&xs);
|
|
|
|
x = hw->win->MouseX - bbox->Left +xs;
|
|
|
|
GetAttr(SCROLLER_Top,hw->objects[OID_VSCROLL],(ULONG *)&ys);
|
|
|
|
y = hw->win->MouseY - bbox->Top + ys;
|
2009-03-07 23:52:08 +03:00
|
|
|
|
2014-11-15 17:39:54 +03:00
|
|
|
ami_gui_free_space_box(bbox);
|
|
|
|
|
2009-03-16 00:44:03 +03:00
|
|
|
switch(code)
|
2009-03-08 19:24:52 +03:00
|
|
|
{
|
2009-03-16 00:44:03 +03:00
|
|
|
case SELECTUP:
|
2014-11-16 18:42:45 +03:00
|
|
|
browser_window_history_click(hw->gw->bw, x, y, false);
|
2009-03-16 00:44:03 +03:00
|
|
|
ami_history_redraw(hw);
|
2014-11-16 18:42:45 +03:00
|
|
|
ami_schedule_redraw(hw->gw->shared, true);
|
2009-03-16 00:44:03 +03:00
|
|
|
break;
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2009-03-16 00:44:03 +03:00
|
|
|
case MIDDLEUP:
|
2014-11-16 18:42:45 +03:00
|
|
|
browser_window_history_click(hw->gw->bw, x, y, true);
|
2009-03-16 00:44:03 +03:00
|
|
|
ami_history_redraw(hw);
|
|
|
|
break;
|
2009-03-08 19:24:52 +03:00
|
|
|
}
|
2009-03-07 23:52:08 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-08 15:52:44 +03:00
|
|
|
|
|
|
|
void ami_history_close(struct history_window *hw)
|
|
|
|
{
|
2009-08-29 18:45:47 +04:00
|
|
|
ami_free_layers(&hw->gg);
|
2014-11-16 18:42:45 +03:00
|
|
|
hw->gw->hw = NULL;
|
2009-03-08 15:52:44 +03:00
|
|
|
DisposeObject(hw->objects[OID_MAIN]);
|
|
|
|
DelObject(hw->node);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ami_history_event(struct history_window *hw)
|
|
|
|
{
|
|
|
|
/* return TRUE if window destroyed */
|
2014-10-16 12:55:01 +04:00
|
|
|
ULONG result = 0;
|
2009-03-08 15:52:44 +03:00
|
|
|
uint16 code;
|
2011-07-23 18:06:13 +04:00
|
|
|
const char *url;
|
2010-03-18 00:00:18 +03:00
|
|
|
struct IBox *bbox;
|
2010-03-18 01:15:03 +03:00
|
|
|
ULONG xs, ys;
|
2009-03-08 15:52:44 +03:00
|
|
|
|
|
|
|
while((result = RA_HandleInput(hw->objects[OID_MAIN],&code)) != WMHI_LASTMSG)
|
|
|
|
{
|
|
|
|
switch(result & WMHI_CLASSMASK) // class
|
|
|
|
{
|
|
|
|
/* no menus yet, copied in as will probably need it later
|
|
|
|
case WMHI_MENUPICK:
|
|
|
|
item = ItemAddress(gwin->win->MenuStrip,code);
|
|
|
|
while (code != MENUNULL)
|
|
|
|
{
|
|
|
|
ami_menupick(code,gwin);
|
|
|
|
if(win_destroyed) break;
|
|
|
|
code = item->NextSelect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
|
2010-03-18 00:00:18 +03:00
|
|
|
case WMHI_MOUSEMOVE:
|
2010-03-18 01:15:03 +03:00
|
|
|
GetAttr(SCROLLER_Top, hw->objects[OID_HSCROLL], (ULONG *)&xs);
|
|
|
|
GetAttr(SCROLLER_Top, hw->objects[OID_VSCROLL], (ULONG *)&ys);
|
2010-03-18 00:00:18 +03:00
|
|
|
|
2014-11-15 17:39:54 +03:00
|
|
|
if(ami_gui_get_space_box(hw->objects[GID_BROWSER], &bbox) != NSERROR_OK) {
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user("NoMemory", "");
|
2014-11-15 17:39:54 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-16 18:42:45 +03:00
|
|
|
url = browser_window_history_position_url(hw->gw->bw,
|
2010-03-18 01:15:03 +03:00
|
|
|
hw->win->MouseX - bbox->Left + xs,
|
|
|
|
hw->win->MouseY - bbox->Top + ys);
|
2010-03-18 00:00:18 +03:00
|
|
|
|
2014-11-15 17:39:54 +03:00
|
|
|
ami_gui_free_space_box(bbox);
|
|
|
|
|
2010-04-10 02:38:51 +04:00
|
|
|
RefreshSetGadgetAttrs((APTR)hw->objects[GID_BROWSER],
|
2010-03-18 00:00:18 +03:00
|
|
|
hw->win, NULL,
|
|
|
|
GA_HintInfo, url,
|
|
|
|
TAG_DONE);
|
|
|
|
break;
|
|
|
|
|
2009-03-08 15:52:44 +03:00
|
|
|
case WMHI_NEWSIZE:
|
|
|
|
ami_history_redraw(hw);
|
|
|
|
break;
|
|
|
|
|
2009-03-08 19:24:52 +03:00
|
|
|
case WMHI_MOUSEBUTTONS:
|
|
|
|
ami_history_click(hw,code);
|
|
|
|
break;
|
|
|
|
|
2009-03-08 15:52:44 +03:00
|
|
|
case WMHI_CLOSEWINDOW:
|
|
|
|
ami_history_close(hw);
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-03-09 02:08:27 +03:00
|
|
|
|
|
|
|
void ami_history_update_extent(struct history_window *hw)
|
|
|
|
{
|
|
|
|
struct IBox *bbox;
|
|
|
|
int width, height;
|
|
|
|
|
2014-11-16 18:42:45 +03:00
|
|
|
browser_window_history_size(hw->gw->bw, &width, &height);
|
2014-11-15 17:39:54 +03:00
|
|
|
if(ami_gui_get_space_box(hw->objects[GID_BROWSER], &bbox) != NSERROR_OK) {
|
2016-05-01 16:00:47 +03:00
|
|
|
amiga_warn_user("NoMemory", "");
|
2014-11-15 17:39:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshSetGadgetAttrs((APTR)hw->objects[OID_VSCROLL], hw->win, NULL,
|
|
|
|
GA_ID, OID_VSCROLL,
|
|
|
|
SCROLLER_Total, height,
|
|
|
|
SCROLLER_Visible, bbox->Height,
|
|
|
|
ICA_TARGET, ICTARGET_IDCMP,
|
2009-03-09 02:08:27 +03:00
|
|
|
TAG_DONE);
|
|
|
|
|
2014-11-15 17:39:54 +03:00
|
|
|
RefreshSetGadgetAttrs((APTR)hw->objects[OID_HSCROLL], hw->win, NULL,
|
|
|
|
GA_ID, OID_HSCROLL,
|
|
|
|
SCROLLER_Total, width,
|
|
|
|
SCROLLER_Visible, bbox->Width,
|
|
|
|
ICA_TARGET, ICTARGET_IDCMP,
|
2009-03-09 02:08:27 +03:00
|
|
|
TAG_DONE);
|
2014-11-15 17:39:54 +03:00
|
|
|
|
|
|
|
ami_gui_free_space_box(bbox);
|
2009-03-09 02:08:27 +03:00
|
|
|
}
|
|
|
|
|
2015-02-24 22:51:51 +03:00
|
|
|
HOOKF(void, ami_history_scroller_hook, Object *, object, struct IntuiMessage *)
|
2009-03-09 02:08:27 +03:00
|
|
|
{
|
2014-10-16 12:55:01 +04:00
|
|
|
ULONG gid;
|
2009-03-09 02:08:27 +03:00
|
|
|
struct history_window *hw = hook->h_Data;
|
|
|
|
|
|
|
|
if (msg->Class == IDCMP_IDCMPUPDATE)
|
|
|
|
{
|
|
|
|
gid = GetTagData( GA_ID, 0, msg->IAddress );
|
|
|
|
|
|
|
|
switch( gid )
|
|
|
|
{
|
|
|
|
case OID_HSCROLL:
|
|
|
|
case OID_VSCROLL:
|
|
|
|
ami_history_redraw(hw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ReplyMsg((struct Message *)msg);
|
|
|
|
}
|