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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-22 16:16:20 +04:00
|
|
|
#include "desktop/browser_private.h"
|
2009-03-07 23:52:08 +03:00
|
|
|
#include "desktop/history_core.h"
|
|
|
|
#include "desktop/plotters.h"
|
2010-12-30 03:53:11 +03:00
|
|
|
#include "amiga/os3support.h"
|
2009-03-07 23:52:08 +03:00
|
|
|
#include "amiga/object.h"
|
|
|
|
#include "amiga/gui.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/url.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include <proto/intuition.h>
|
2009-03-08 15:52:44 +03:00
|
|
|
#include "amiga/history_local.h"
|
|
|
|
#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>
|
|
|
|
#include "utils/messages.h"
|
2011-02-27 01:24:41 +03:00
|
|
|
#include "graphics/rpattr.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>
|
|
|
|
|
|
|
|
static struct history *history_current = 0;
|
|
|
|
/* Last position of mouse in window. */
|
|
|
|
static int mouse_x = 0;
|
|
|
|
/* Last position of mouse in window. */
|
|
|
|
static int mouse_y = 0;
|
2009-03-08 15:52:44 +03:00
|
|
|
static struct history_window *hwindow;
|
2009-03-07 23:52:08 +03:00
|
|
|
|
2009-03-09 02:08:27 +03:00
|
|
|
void ami_history_update_extent(struct history_window *hw);
|
|
|
|
void ami_history_redraw(struct history_window *hw);
|
|
|
|
static void ami_history_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg);
|
|
|
|
|
2009-03-07 23:52:08 +03:00
|
|
|
/**
|
|
|
|
* Open history window.
|
|
|
|
*
|
|
|
|
* \param bw browser window to open history for
|
|
|
|
* \param history history to open
|
|
|
|
* \param at_pointer open the window at the pointer
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ami_history_open(struct browser_window *bw, struct history *history)
|
|
|
|
{
|
|
|
|
int width, height;
|
2009-03-09 02:08:27 +03:00
|
|
|
struct IBox *bbox;
|
2009-03-07 23:52:08 +03:00
|
|
|
|
|
|
|
assert(history);
|
|
|
|
|
|
|
|
history_current = history;
|
|
|
|
|
2009-03-08 19:24:52 +03:00
|
|
|
if(!hwindow)
|
|
|
|
{
|
|
|
|
hwindow = AllocVec(sizeof(struct history_window),MEMF_CLEAR | MEMF_PRIVATE);
|
|
|
|
|
2012-02-25 22:42:33 +04:00
|
|
|
ami_init_layers(&hwindow->gg, scrn->Width, scrn->Height);
|
2009-08-29 18:41:24 +04:00
|
|
|
|
2009-03-08 19:24:52 +03:00
|
|
|
hwindow->bw = bw;
|
|
|
|
history_size(history, &width, &height);
|
|
|
|
|
2009-03-09 02:08:27 +03:00
|
|
|
hwindow->scrollerhook.h_Entry = (void *)ami_history_scroller_hook;
|
|
|
|
hwindow->scrollerhook.h_Data = hwindow;
|
|
|
|
|
2009-03-08 19:24:52 +03:00
|
|
|
hwindow->objects[OID_MAIN] = WindowObject,
|
|
|
|
WA_ScreenTitle,nsscreentitle,
|
|
|
|
WA_Title,messages_get("History"),
|
|
|
|
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,
|
|
|
|
WINDOW_UserData,hwindow,
|
|
|
|
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,
|
|
|
|
WINDOW_IDCMPHook,&hwindow->scrollerhook,
|
|
|
|
WINDOW_IDCMPHookBits,IDCMP_IDCMPUPDATE,
|
|
|
|
// WA_ReportMouse,TRUE,
|
2009-03-08 19:24:52 +03:00
|
|
|
WA_IDCMP,IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE, // | IDCMP_MOUSEMOVE,
|
2010-04-10 02:38:51 +04:00
|
|
|
WINDOW_ParentGroup, hwindow->objects[GID_MAIN] = VGroupObject,
|
|
|
|
LAYOUT_AddChild, hwindow->objects[GID_BROWSER] = SpaceObject,
|
2009-03-08 19:24:52 +03:00
|
|
|
GA_ID,GID_BROWSER,
|
|
|
|
// SPACE_MinWidth,width,
|
|
|
|
// SPACE_MinHeight,height,
|
|
|
|
SpaceEnd,
|
|
|
|
EndGroup,
|
|
|
|
EndWindow;
|
|
|
|
|
|
|
|
hwindow->win = (struct Window *)RA_OpenWindow(hwindow->objects[OID_MAIN]);
|
|
|
|
// hwindow->bw->window = hwindow;
|
|
|
|
hwindow->node = AddObject(window_list,AMINS_HISTORYWINDOW);
|
|
|
|
hwindow->node->objstruct = hwindow;
|
2009-03-09 02:08:27 +03:00
|
|
|
|
|
|
|
GetAttr(WINDOW_HorizObject,hwindow->objects[OID_MAIN],(ULONG *)&hwindow->objects[OID_HSCROLL]);
|
|
|
|
GetAttr(WINDOW_VertObject,hwindow->objects[OID_MAIN],(ULONG *)&hwindow->objects[OID_VSCROLL]);
|
|
|
|
|
|
|
|
RefreshSetGadgetAttrs((APTR)hwindow->objects[OID_VSCROLL],hwindow->win,NULL,
|
|
|
|
GA_ID,OID_VSCROLL,
|
|
|
|
SCROLLER_Top,0,
|
|
|
|
ICA_TARGET,ICTARGET_IDCMP,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
RefreshSetGadgetAttrs((APTR)hwindow->objects[OID_HSCROLL],hwindow->win,NULL,
|
|
|
|
GA_ID,OID_HSCROLL,
|
|
|
|
SCROLLER_Top,0,
|
|
|
|
ICA_TARGET,ICTARGET_IDCMP,
|
|
|
|
TAG_DONE);
|
2009-03-08 19:24:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
hwindow->bw = bw;
|
2009-03-15 14:21:46 +03:00
|
|
|
bw->window->hw = hwindow;
|
2009-03-08 15:52:44 +03:00
|
|
|
ami_history_redraw(hwindow);
|
2009-03-07 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw history window.
|
|
|
|
*/
|
|
|
|
|
2009-03-08 15:52:44 +03:00
|
|
|
void ami_history_redraw(struct history_window *hw)
|
2009-03-07 23:52:08 +03:00
|
|
|
{
|
2009-03-08 19:24:52 +03:00
|
|
|
struct IBox *bbox;
|
2009-03-09 02:08:27 +03:00
|
|
|
ULONG xs,ys;
|
2011-06-30 19:48:07 +04:00
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
2011-12-24 02:39:25 +04:00
|
|
|
.background_images = true,
|
2011-06-30 19:48:07 +04:00
|
|
|
.plot = &amiplot
|
|
|
|
};
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2010-04-10 02:38:51 +04:00
|
|
|
GetAttr(SPACE_AreaBox,hw->objects[GID_BROWSER],(ULONG *)&bbox);
|
2009-03-09 02:08:27 +03:00
|
|
|
GetAttr(SCROLLER_Top,hw->objects[OID_HSCROLL],(ULONG *)&xs);
|
|
|
|
GetAttr(SCROLLER_Top,hw->objects[OID_VSCROLL],(ULONG *)&ys);
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2009-08-29 18:41:24 +04:00
|
|
|
glob = &hw->gg;
|
2011-02-27 01:24:41 +03:00
|
|
|
|
2011-03-15 03:08:06 +03:00
|
|
|
SetRPAttrs(glob->rp, RPTAG_APenColor, 0xffffffff, TAG_DONE);
|
|
|
|
RectFill(glob->rp, 0, 0, bbox->Width - 1, bbox->Height - 1);
|
2009-03-09 02:08:27 +03:00
|
|
|
|
|
|
|
history_redraw_rectangle(history_current, xs, ys,
|
2011-06-30 19:48:07 +04:00
|
|
|
bbox->Width + xs, bbox->Height + ys, 0, 0, &ctx);
|
2009-03-09 02:08:27 +03:00
|
|
|
|
2009-08-29 18:41:24 +04:00
|
|
|
glob = &browserglob;
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2009-08-29 18:41:24 +04:00
|
|
|
ami_clearclipreg(&hw->gg);
|
2009-03-09 02:08:27 +03:00
|
|
|
ami_history_update_extent(hw);
|
|
|
|
|
2009-08-29 18:41:24 +04:00
|
|
|
BltBitMapRastPort(hw->gg.bm, 0, 0, hw->win->RPort,
|
2009-07-07 23:28:34 +04:00
|
|
|
bbox->Left, bbox->Top, bbox->Width, bbox->Height, 0x0C0);
|
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
|
|
|
|
*/
|
|
|
|
|
2009-03-08 19:24:52 +03:00
|
|
|
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;
|
2009-03-09 02:08:27 +03:00
|
|
|
ULONG width,height,xs,ys;
|
2009-03-08 19:24:52 +03:00
|
|
|
|
2010-04-10 02:38:51 +04:00
|
|
|
GetAttr(SPACE_AreaBox,hw->objects[GID_BROWSER],(ULONG *)&bbox);
|
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
|
|
|
|
2009-03-08 19:24:52 +03:00
|
|
|
width=bbox->Width;
|
|
|
|
height=bbox->Height;
|
|
|
|
|
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:
|
|
|
|
history_click(hw->bw,history_current,x,y,false);
|
|
|
|
ami_history_redraw(hw);
|
2013-04-04 22:46:33 +04:00
|
|
|
ami_schedule_redraw(hw->bw->window->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:
|
|
|
|
history_click(hw->bw,history_current,x,y,true);
|
|
|
|
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);
|
2009-03-15 14:21:46 +03:00
|
|
|
hw->bw->window->hw = NULL;
|
2009-03-08 15:52:44 +03:00
|
|
|
DisposeObject(hw->objects[OID_MAIN]);
|
|
|
|
DelObject(hw->node);
|
|
|
|
hwindow = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ami_history_event(struct history_window *hw)
|
|
|
|
{
|
|
|
|
/* return TRUE if window destroyed */
|
|
|
|
ULONG class,result,relevent = 0;
|
|
|
|
uint16 code;
|
|
|
|
struct MenuItem *item;
|
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-04-10 02:38:51 +04:00
|
|
|
GetAttr(SPACE_AreaBox, hw->objects[GID_BROWSER], (ULONG *)&bbox);
|
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
|
|
|
|
|
|
|
url = history_position_url(history_current,
|
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
|
|
|
|
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;
|
|
|
|
|
|
|
|
history_size(hw->bw->history, &width, &height);
|
2010-04-10 02:38:51 +04:00
|
|
|
GetAttr(SPACE_AreaBox,hw->objects[GID_BROWSER],(ULONG *)&bbox);
|
2009-03-09 02:08:27 +03:00
|
|
|
|
|
|
|
RefreshSetGadgetAttrs((APTR)hw->objects[OID_VSCROLL],hw->win,NULL,
|
|
|
|
GA_ID,OID_VSCROLL,
|
|
|
|
SCROLLER_Total,height,
|
|
|
|
SCROLLER_Visible,bbox->Height,
|
|
|
|
// SCROLLER_Top,0,
|
|
|
|
ICA_TARGET,ICTARGET_IDCMP,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
RefreshSetGadgetAttrs((APTR)hw->objects[OID_HSCROLL],hw->win,NULL,
|
|
|
|
GA_ID,OID_HSCROLL,
|
|
|
|
SCROLLER_Total,width,
|
|
|
|
SCROLLER_Visible,bbox->Width,
|
|
|
|
// SCROLLER_Top,0,
|
|
|
|
ICA_TARGET,ICTARGET_IDCMP,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ami_history_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg)
|
|
|
|
{
|
|
|
|
ULONG gid,x,y;
|
|
|
|
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);
|
|
|
|
}
|