From 30b09368e7980def81ccfd7b4038225e7ec13ed9 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 25 Oct 2008 23:22:34 +0000 Subject: Track the current/last used browser window (at the moment, just for ARexx). Extended ARexx port. First two are primarily for openurl.library: * OPEN now takes a parameter NEW=NEWWINDOW/S to open the URL in a new window (default is to open in the current browser window) * TOFRONT will bring NetSurf's screen to the front (this may be extended in the future to bring the current browser window to the front - which might be better for when it is running on the WB screen) Next is to make it easy to support getvideo.rexx: * GETURL returns the URL of the current browser window in RESULT GetVideo.nsrx script will get the current URL and pass it to rexx:getvideo.rexx Currently there is no way to call ARexx scripts directly from NetSurf, or any way to specify whether to save, play or saveplay the video without editing the script. [clipboard.c/clipboard.h were missing from previous commit] svn path=/trunk/netsurf/; revision=5631 --- amiga/arexx.c | 31 +++++- amiga/clipboard.c | 238 ++++++++++++++++++++++++++++++++++++++++++ amiga/clipboard.h | 24 +++++ amiga/dist/Rexx/GetVideo.nsrx | 26 +++++ amiga/gui.c | 13 ++- amiga/gui.h | 1 + 6 files changed, 328 insertions(+), 5 deletions(-) create mode 100755 amiga/clipboard.c create mode 100755 amiga/clipboard.h create mode 100755 amiga/dist/Rexx/GetVideo.nsrx diff --git a/amiga/arexx.c b/amiga/arexx.c index 51fe0b835..bbd7b9aa8 100755 --- a/amiga/arexx.c +++ b/amiga/arexx.c @@ -27,15 +27,23 @@ enum { RX_OPEN=0, RX_QUIT, + RX_TOFRONT, + RX_GETURL }; +STATIC char result[100]; + STATIC VOID rx_open(struct ARexxCmd *, struct RexxMsg *); STATIC VOID rx_quit(struct ARexxCmd *, struct RexxMsg *); +STATIC VOID rx_tofront(struct ARexxCmd *, struct RexxMsg *); +STATIC VOID rx_geturl(struct ARexxCmd *, struct RexxMsg *); STATIC struct ARexxCmd Commands[] = { - {"OPEN",RX_OPEN,rx_open,"URL/A", 0, NULL, 0, 0, NULL }, + {"OPEN",RX_OPEN,rx_open,"URL/A,NEW=NEWWINDOW/S", 0, NULL, 0, 0, NULL }, {"QUIT",RX_QUIT,rx_quit,NULL, 0, NULL, 0, 0, NULL }, + {"TOFRONT",RX_TOFRONT,rx_tofront,NULL, 0, NULL, 0, 0, NULL }, + {"GETURL",RX_GETURL,rx_geturl,NULL, 0, NULL, 0, 0, NULL }, { NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL } }; @@ -65,10 +73,29 @@ void ami_arexx_cleanup() STATIC VOID rx_open(struct ARexxCmd *cmd, struct RexxMsg *rxm __attribute__((unused))) { - browser_window_create((char *)cmd->ac_ArgList[0],NULL,NULL,true,false); + if(cmd->ac_ArgList[1]) + { + browser_window_create((char *)cmd->ac_ArgList[0],NULL,NULL,true,false); + } + else + { + browser_window_go(curbw,(char *)cmd->ac_ArgList[0],NULL,true); + } } STATIC VOID rx_quit(struct ARexxCmd *cmd, struct RexxMsg *rxm __attribute__((unused))) { ami_quit_netsurf(); } + +STATIC VOID rx_tofront(struct ARexxCmd *cmd, struct RexxMsg *rxm __attribute__((unused))) +{ + ScreenToFront(scrn); +} + +STATIC VOID rx_geturl(struct ARexxCmd *cmd, struct RexxMsg *rxm __attribute__((unused))) +{ + strcpy(result,curbw->current_content->url); + cmd->ac_Result = result; +} + diff --git a/amiga/clipboard.c b/amiga/clipboard.c new file mode 100755 index 000000000..c31c5ea05 --- /dev/null +++ b/amiga/clipboard.c @@ -0,0 +1,238 @@ +/* + * Copyright 2008 Chris Young + * + * 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 . + */ + +#include "desktop/gui.h" +#include +#include "amiga/iff_cset.h" +#include +#include +#include "amiga/options.h" +#include "amiga/gui.h" +#include +#include "amiga/utf8.h" +#include "utils/utf8.h" +#include "desktop/selection.h" + + +struct IFFHandle *iffh = NULL; + +void ami_clipboard_init(void) +{ + if(iffh = AllocIFF()) + { + if(iffh->iff_Stream = (ULONG)OpenClipboard(0)) + { + InitIFFasClip(iffh); + } + } +} + +void ami_clipboard_free(void) +{ + if(iffh->iff_Stream) CloseClipboard((struct ClipboardHandle *)iffh->iff_Stream); + if(iffh) FreeIFF(iffh); +} + +void gui_drag_save_selection(struct selection *s, struct gui_window *g) +{ +} + +void gui_start_selection(struct gui_window *g) +{ +} + +void gui_paste_from_clipboard(struct gui_window *g, int x, int y) +{ + /* This and the other clipboard code is heavily based on the RKRM examples */ + struct ContextNode *cn; + ULONG rlen=0,error; + struct CSet cset; + char *clip; + STRPTR readbuf = AllocVec(1024,MEMF_CLEAR); + + cset.CodeSet = 0; + + if(OpenIFF(iffh,IFFF_READ)) return; + if(StopChunk(iffh,ID_FTXT,ID_CHRS)) return; + if(StopChunk(iffh,ID_FTXT,ID_CSET)) return; + + while(1) + { + error = ParseIFF(iffh,IFFPARSE_SCAN); + if(error == IFFERR_EOC) continue; + else if(error) break; + + cn = CurrentChunk(iffh); + + if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CSET)) + { + rlen = ReadChunkBytes(iffh,&cset,24); + } + + if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CHRS)) + { + while((rlen = ReadChunkBytes(iffh,readbuf,1024)) > 0) + { + if(cset.CodeSet == 0) + { + utf8_from_local_encoding(readbuf,rlen,&clip); + } + else + { + utf8_from_enc(readbuf,parserutils_charset_mibenum_to_name(cset.CodeSet),rlen,&clip); + } + + browser_window_paste_text(g->shared->bw,clip,rlen,true); + } + if(rlen < 0) error = rlen; + } + } + CloseIFF(iffh); +} + +bool gui_empty_clipboard(void) +{ +} + +bool gui_add_to_clipboard(const char *text, size_t length, bool space) +{ + char *buffer; + if(option_utf8_clipboard) + { + WriteChunkBytes(iffh,text,length); + } + else + { + utf8_to_local_encoding(text,length,&buffer); + if(buffer) WriteChunkBytes(iffh,buffer,strlen(buffer)); + ami_utf8_free(buffer); + } + + if(space) WriteChunkBytes(iffh," ",1); + + return true; +} + +bool gui_commit_clipboard(void) +{ + if(iffh) CloseIFF(iffh); + + return true; +} + +bool ami_clipboard_copy(const char *text, size_t length, struct box *box, + void *handle, const char *whitespace_text,size_t whitespace_length) +{ + if(!(PushChunk(iffh,0,ID_CHRS,IFFSIZE_UNKNOWN))) + { + if (whitespace_text) + { + if(!gui_add_to_clipboard(whitespace_text,whitespace_length, false)) return false; + } + + if(text) + { + if (!gui_add_to_clipboard(text, length, box->space)) return false; + } + + PopChunk(iffh); + } + else + { + PopChunk(iffh); + return false; + } + + return true; +} + +bool gui_copy_to_clipboard(struct selection *s) +{ + struct CSet cset = {0}; + + if(!(OpenIFF(iffh,IFFF_WRITE))) + { + if(!(PushChunk(iffh,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN))) + { + if(option_utf8_clipboard) + { + if(!(PushChunk(iffh,0,ID_CSET,24))) + { + cset.CodeSet = 106; // UTF-8 + WriteChunkBytes(iffh,&cset,24); + PopChunk(iffh); + } + } + + if (s->defined && selection_traverse(s, ami_clipboard_copy, NULL)) + { + gui_commit_clipboard(); + return true; + } + } + else + { + PopChunk(iffh); + } + CloseIFF(iffh); + } + + return false; +} + +bool ami_easy_clipboard(char *text) +{ + struct CSet cset = {0}; + + if(!(OpenIFF(iffh,IFFF_WRITE))) + { + if(!(PushChunk(iffh,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN))) + { + if(option_utf8_clipboard) + { + if(!(PushChunk(iffh,0,ID_CSET,24))) + { + cset.CodeSet = 106; // UTF-8 + WriteChunkBytes(iffh,&cset,24); + PopChunk(iffh); + } + } + + if(!(PushChunk(iffh,0,ID_CHRS,IFFSIZE_UNKNOWN))) + { + if(gui_add_to_clipboard(text,strlen(text),false)) + { + PopChunk(iffh); + gui_commit_clipboard(); + return true; + } + } + else + { + PopChunk(iffh); + } + } + else + { + PopChunk(iffh); + } + CloseIFF(iffh); + } + + return false; +} diff --git a/amiga/clipboard.h b/amiga/clipboard.h new file mode 100755 index 000000000..45608a4de --- /dev/null +++ b/amiga/clipboard.h @@ -0,0 +1,24 @@ +/* + * Copyright 2008 Chris Young + * + * 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 . + */ + +#ifndef AMIGA_CLIPBOARD_H +#define AMIGA_CLIPBOARD_H +void ami_clipboard_init(void); +void ami_clipboard_free(void); +bool ami_easy_clipboard(char *text); +#endif diff --git a/amiga/dist/Rexx/GetVideo.nsrx b/amiga/dist/Rexx/GetVideo.nsrx new file mode 100755 index 000000000..000286baf --- /dev/null +++ b/amiga/dist/Rexx/GetVideo.nsrx @@ -0,0 +1,26 @@ +/* + * Copyright 2008 Chris Young + * + * 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 . + */ + +/* This script launches getvideo.rexx (Aminet:comm/www/getvideo.lha) */ + +options results +address netsurf + +geturl + +address REXX 'rexx:getvideo.rexx' result 'save "ram:"' diff --git a/amiga/gui.c b/amiga/gui.c index 17382d9ef..f7e107360 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -91,8 +91,6 @@ #include #include -struct browser_window *curbw; - char *default_stylesheet_url; char *adblock_stylesheet_url; struct gui_window *search_current_window = NULL; @@ -739,6 +737,10 @@ void ami_handle_msg(void) ami_close_all_tabs(gwin); break; + case WMHI_ACTIVE: + curbw = gwin->bw; + break; + case WMHI_INTUITICK: break; @@ -981,6 +983,7 @@ void ami_switch_tab(struct gui_window_2 *gwin,bool redraw) GetClickTabNodeAttrs(tabnode, TNA_UserData,&gwin->bw, TAG_DONE); + curbw = gwin->bw; ami_update_buttons(gwin); @@ -1339,7 +1342,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE | - IDCMP_INTUITICKS, + IDCMP_INTUITICKS | IDCMP_ACTIVEWINDOW, // WINDOW_IconifyGadget, TRUE, WINDOW_NewMenu,menu, WINDOW_HorizProp,1, @@ -1593,6 +1596,8 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, ICA_TARGET,ICTARGET_IDCMP, TAG_DONE); + curbw = bw; + gwin->shared->node = AddObject(window_list,AMINS_WINDOW); gwin->shared->node->objstruct = gwin->shared; @@ -1656,6 +1661,8 @@ void gui_window_destroy(struct gui_window *g) return; } + curbw = NULL; + DisposeObject(g->shared->objects[OID_MAIN]); DeleteLayer(0,g->shared->rp.Layer); DisposeLayerInfo(g->shared->layerinfo); diff --git a/amiga/gui.h b/amiga/gui.h index 9e453ac85..aecd888c4 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -134,4 +134,5 @@ STRPTR nsscreentitle; struct FileRequester *filereq; struct MsgPort *sport; bool win_destroyed; +struct browser_window *curbw; #endif -- cgit v1.2.3