2008-10-26 02:22:34 +03:00
|
|
|
/*
|
2012-02-12 21:56:25 +04:00
|
|
|
* Copyright 2008-2012 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
2008-10-26 02:22:34 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "desktop/gui.h"
|
2010-07-24 20:39:37 +04:00
|
|
|
#include "desktop/selection.h"
|
2010-07-24 23:57:27 +04:00
|
|
|
#include "desktop/textinput.h"
|
2012-03-27 00:25:10 +04:00
|
|
|
#include "render/box.h"
|
|
|
|
#include "utils/utf8.h"
|
2010-07-24 20:39:37 +04:00
|
|
|
|
2011-07-23 18:06:13 +04:00
|
|
|
#include "amiga/bitmap.h"
|
2011-04-29 22:15:20 +04:00
|
|
|
#include "amiga/clipboard.h"
|
2011-07-23 18:06:13 +04:00
|
|
|
#include "amiga/drag.h"
|
|
|
|
#include "amiga/filetype.h"
|
2008-10-26 02:22:34 +03:00
|
|
|
#include "amiga/gui.h"
|
2011-07-23 18:06:13 +04:00
|
|
|
#include "amiga/iff_cset.h"
|
2009-05-19 11:23:56 +04:00
|
|
|
#include "amiga/iff_dr2d.h"
|
2010-07-24 20:39:37 +04:00
|
|
|
#include "amiga/menu.h"
|
2012-03-22 13:34:34 +04:00
|
|
|
#include "desktop/options.h"
|
2011-07-23 18:06:13 +04:00
|
|
|
#include "amiga/utf8.h"
|
2010-07-24 20:39:37 +04:00
|
|
|
|
|
|
|
#include <proto/iffparse.h>
|
|
|
|
#include <proto/intuition.h>
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <proto/datatypes.h>
|
2010-05-04 00:49:15 +04:00
|
|
|
#include <proto/diskfont.h>
|
2010-07-24 20:39:37 +04:00
|
|
|
|
2010-05-04 00:49:15 +04:00
|
|
|
#include <diskfont/diskfonttag.h>
|
2010-07-24 20:39:37 +04:00
|
|
|
#include <datatypes/textclass.h>
|
|
|
|
#include <datatypes/pictureclass.h>
|
2008-10-26 02:22:34 +03:00
|
|
|
|
2012-08-03 21:33:49 +04:00
|
|
|
#define ID_UTF8 MAKE_ID('U','T','F','8')
|
|
|
|
|
2008-10-26 02:22:34 +03:00
|
|
|
struct IFFHandle *iffh = NULL;
|
|
|
|
|
2010-07-24 23:57:27 +04:00
|
|
|
bool ami_add_to_clipboard(const char *text, size_t length, bool space);
|
2011-04-29 22:15:20 +04:00
|
|
|
static bool ami_copy_selection(const char *text, size_t length,
|
|
|
|
struct box *box, void *handle, const char *whitespace_text,
|
|
|
|
size_t whitespace_length);
|
2010-07-24 23:57:27 +04:00
|
|
|
|
2012-08-04 00:02:29 +04:00
|
|
|
static LONG ami_clipboard_iffp_do_nothing(struct Hook *hook, void *object, LONG *cmd)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ami_clipboard_iffp_clear_stopchunk(struct IFFHandle *iffh, ULONG iff_type, ULONG iff_chunk)
|
|
|
|
{
|
|
|
|
static struct Hook entry_hook;
|
|
|
|
|
|
|
|
entry_hook.h_Entry = (void *)ami_clipboard_iffp_do_nothing;
|
|
|
|
entry_hook.h_Data = 0;
|
|
|
|
|
|
|
|
EntryHandler(iffh, iff_type, iff_chunk, IFFSLI_TOP, &entry_hook, NULL);
|
|
|
|
}
|
|
|
|
|
2010-10-24 22:07:11 +04:00
|
|
|
struct IFFHandle *ami_clipboard_init_internal(int unit)
|
2008-10-26 02:22:34 +03:00
|
|
|
{
|
2010-10-24 22:07:11 +04:00
|
|
|
struct IFFHandle *iffhandle = NULL;
|
|
|
|
|
|
|
|
if(iffhandle = AllocIFF())
|
2008-10-26 02:22:34 +03:00
|
|
|
{
|
2010-10-24 22:07:11 +04:00
|
|
|
if(iffhandle->iff_Stream = (ULONG)OpenClipboard(unit))
|
2008-10-26 02:22:34 +03:00
|
|
|
{
|
2010-10-24 22:07:11 +04:00
|
|
|
InitIFFasClip(iffhandle);
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
}
|
2010-10-24 22:07:11 +04:00
|
|
|
|
|
|
|
return iffhandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ami_clipboard_init(void)
|
|
|
|
{
|
|
|
|
iffh = ami_clipboard_init_internal(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ami_clipboard_free_internal(struct IFFHandle *iffhandle)
|
|
|
|
{
|
|
|
|
if(iffhandle->iff_Stream) CloseClipboard((struct ClipboardHandle *)iffhandle->iff_Stream);
|
|
|
|
if(iffhandle) FreeIFF(iffhandle);
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ami_clipboard_free(void)
|
|
|
|
{
|
2010-10-24 22:07:11 +04:00
|
|
|
ami_clipboard_free_internal(iffh);
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void gui_start_selection(struct gui_window *g)
|
|
|
|
{
|
2010-07-24 20:39:37 +04:00
|
|
|
if(!g) return;
|
|
|
|
if(!g->shared->win) return;
|
2012-03-22 13:34:34 +04:00
|
|
|
if(nsoption_bool(kiosk_mode) == true) return;
|
2010-07-24 20:39:37 +04:00
|
|
|
|
|
|
|
OnMenu(g->shared->win, AMI_MENU_CLEAR);
|
|
|
|
OnMenu(g->shared->win, AMI_MENU_COPY);
|
|
|
|
|
2011-07-13 17:38:38 +04:00
|
|
|
if(selection_read_only(browser_window_get_selection(g->shared->bw)) == false)
|
2010-07-24 20:39:37 +04:00
|
|
|
OnMenu(g->shared->win, AMI_MENU_CUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_clear_selection(struct gui_window *g)
|
|
|
|
{
|
|
|
|
if(!g) return;
|
|
|
|
if(!g->shared->win) return;
|
2012-03-22 13:34:34 +04:00
|
|
|
if(nsoption_bool(kiosk_mode) == true) return;
|
2010-07-24 20:39:37 +04:00
|
|
|
|
|
|
|
OffMenu(g->shared->win, AMI_MENU_CLEAR);
|
|
|
|
OffMenu(g->shared->win, AMI_MENU_CUT);
|
|
|
|
OffMenu(g->shared->win, AMI_MENU_COPY);
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
|
2012-08-03 22:19:04 +04:00
|
|
|
bool ami_clipboard_check_for_utf8(struct IFFHandle *iffh) {
|
|
|
|
struct ContextNode *cn;
|
|
|
|
ULONG error;
|
|
|
|
bool utf8_chunk = false;
|
|
|
|
|
|
|
|
if(OpenIFF(iffh, IFFF_READ)) return false;
|
2012-08-04 00:02:29 +04:00
|
|
|
|
|
|
|
ami_clipboard_iffp_clear_stopchunk(iffh, ID_FTXT, ID_CSET);
|
|
|
|
ami_clipboard_iffp_clear_stopchunk(iffh, ID_FTXT, ID_CHRS);
|
|
|
|
|
2012-08-03 22:19:04 +04:00
|
|
|
if(!StopChunk(iffh, ID_FTXT, ID_UTF8)) {
|
|
|
|
error = ParseIFF(iffh, IFFPARSE_SCAN);
|
|
|
|
if(error != IFFERR_EOF)
|
|
|
|
utf8_chunk = true; /* or a real error, but that'll get caught later */
|
|
|
|
}
|
|
|
|
CloseIFF(iffh);
|
|
|
|
|
|
|
|
return utf8_chunk;
|
|
|
|
}
|
|
|
|
|
2008-10-26 02:22:34 +03:00
|
|
|
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;
|
2012-01-15 19:58:26 +04:00
|
|
|
LONG codeset = 0;
|
2008-10-26 02:22:34 +03:00
|
|
|
char *clip;
|
2012-08-03 22:19:04 +04:00
|
|
|
bool utf8_chunks = false;
|
2008-11-02 03:21:49 +03:00
|
|
|
STRPTR readbuf = AllocVec(1024,MEMF_PRIVATE | MEMF_CLEAR);
|
2008-10-26 02:22:34 +03:00
|
|
|
|
|
|
|
cset.CodeSet = 0;
|
|
|
|
|
2012-08-03 22:19:04 +04:00
|
|
|
if(ami_clipboard_check_for_utf8(iffh))
|
|
|
|
utf8_chunks = true;
|
|
|
|
|
2008-10-26 02:22:34 +03:00
|
|
|
if(OpenIFF(iffh,IFFF_READ)) return;
|
2012-08-03 22:19:04 +04:00
|
|
|
|
|
|
|
if(utf8_chunks == false) {
|
|
|
|
if(StopChunk(iffh,ID_FTXT,ID_CHRS)) return;
|
|
|
|
if(StopChunk(iffh,ID_FTXT,ID_CSET)) return;
|
|
|
|
} else {
|
|
|
|
if(StopChunk(iffh,ID_FTXT,ID_UTF8)) return;
|
|
|
|
}
|
|
|
|
|
2008-10-26 02:22:34 +03:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
error = ParseIFF(iffh,IFFPARSE_SCAN);
|
|
|
|
if(error == IFFERR_EOC) continue;
|
|
|
|
else if(error) break;
|
|
|
|
|
|
|
|
cn = CurrentChunk(iffh);
|
|
|
|
|
2012-08-03 22:19:04 +04:00
|
|
|
if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CSET)&&(utf8_chunks == false))
|
2008-10-26 02:22:34 +03:00
|
|
|
{
|
2012-01-15 20:37:36 +04:00
|
|
|
rlen = ReadChunkBytes(iffh,&cset,32);
|
2012-01-15 19:58:26 +04:00
|
|
|
if(cset.CodeSet == 1) codeset = 106;
|
|
|
|
else codeset = cset.CodeSet;
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
|
2012-08-03 22:19:04 +04:00
|
|
|
if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_CHRS)&&(utf8_chunks == false))
|
2008-10-26 02:22:34 +03:00
|
|
|
{
|
|
|
|
while((rlen = ReadChunkBytes(iffh,readbuf,1024)) > 0)
|
|
|
|
{
|
2012-01-15 19:58:26 +04:00
|
|
|
if(codeset == 0)
|
2008-10-26 02:22:34 +03:00
|
|
|
{
|
|
|
|
utf8_from_local_encoding(readbuf,rlen,&clip);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-04 00:49:15 +04:00
|
|
|
utf8_from_enc(readbuf,
|
2011-07-23 18:06:13 +04:00
|
|
|
(const char *)ObtainCharsetInfo(DFCS_NUMBER,
|
2012-01-15 19:58:26 +04:00
|
|
|
codeset, DFCS_MIMENAME),
|
2010-05-04 00:49:15 +04:00
|
|
|
rlen, &clip);
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
browser_window_paste_text(g->shared->bw,clip,rlen,true);
|
|
|
|
}
|
|
|
|
if(rlen < 0) error = rlen;
|
|
|
|
}
|
2012-08-03 22:19:04 +04:00
|
|
|
|
|
|
|
if((cn)&&(cn->cn_Type == ID_FTXT)&&(cn->cn_ID == ID_UTF8)&&(utf8_chunks == true))
|
|
|
|
{
|
|
|
|
while((rlen = ReadChunkBytes(iffh, readbuf, 1024)) > 0)
|
|
|
|
{
|
|
|
|
browser_window_paste_text(g->shared->bw, readbuf, rlen, true);
|
|
|
|
}
|
|
|
|
if(rlen < 0) error = rlen;
|
|
|
|
}
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
CloseIFF(iffh);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gui_empty_clipboard(void)
|
|
|
|
{
|
2010-07-24 23:57:27 +04:00
|
|
|
/* Put a half-completed FTXT on the clipboard and leave it open for more additions */
|
|
|
|
|
|
|
|
struct CSet cset = {0};
|
|
|
|
|
|
|
|
if(!(OpenIFF(iffh,IFFF_WRITE)))
|
|
|
|
{
|
|
|
|
if(!(PushChunk(iffh,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN)))
|
|
|
|
{
|
2012-08-04 00:04:38 +04:00
|
|
|
if(nsoption_bool(utf8_clipboard))
|
2010-07-24 23:57:27 +04:00
|
|
|
{
|
2012-01-15 20:37:36 +04:00
|
|
|
if(!(PushChunk(iffh,0,ID_CSET,32)))
|
2010-07-24 23:57:27 +04:00
|
|
|
{
|
|
|
|
cset.CodeSet = 106; // UTF-8
|
2012-01-15 20:37:36 +04:00
|
|
|
WriteChunkBytes(iffh,&cset,32);
|
2010-07-24 23:57:27 +04:00
|
|
|
PopChunk(iffh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PopChunk(iffh);
|
2010-07-25 00:18:56 +04:00
|
|
|
return false;
|
2010-07-24 23:57:27 +04:00
|
|
|
}
|
2010-07-25 00:18:56 +04:00
|
|
|
return true;
|
2010-07-24 23:57:27 +04:00
|
|
|
}
|
2010-07-25 00:18:56 +04:00
|
|
|
return false;
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool gui_add_to_clipboard(const char *text, size_t length, bool space)
|
2010-07-24 23:57:27 +04:00
|
|
|
{
|
|
|
|
/* This might crash or at least not work if gui_empty_clipboard isn't called first,
|
|
|
|
and gui_commit_clipboard after.
|
|
|
|
These only seem to be called from desktop/textinput.c in this specific order, if they
|
|
|
|
are added elsewhere this might need a rewrite. */
|
|
|
|
|
2008-10-26 02:22:34 +03:00
|
|
|
char *buffer;
|
2010-07-24 23:57:27 +04:00
|
|
|
|
2012-08-03 21:28:07 +04:00
|
|
|
if(text == NULL) return true;
|
|
|
|
|
2012-08-03 21:15:16 +04:00
|
|
|
if(!(PushChunk(iffh,0,ID_CHRS,IFFSIZE_UNKNOWN))) {
|
2012-08-04 00:04:38 +04:00
|
|
|
if(nsoption_bool(utf8_clipboard)) {
|
2012-08-03 21:15:16 +04:00
|
|
|
WriteChunkBytes(iffh,text,length);
|
|
|
|
} else {
|
|
|
|
buffer = ami_utf8_easy(text);
|
2011-04-30 14:54:02 +04:00
|
|
|
|
2012-08-03 21:15:16 +04:00
|
|
|
if(buffer) {
|
|
|
|
char *p;
|
2011-04-30 14:54:02 +04:00
|
|
|
|
2012-08-03 21:15:16 +04:00
|
|
|
p = buffer;
|
2011-04-30 14:54:02 +04:00
|
|
|
|
2012-08-03 21:15:16 +04:00
|
|
|
while(*p != '\0') {
|
|
|
|
if(*p == 0xa0) *p = 0x20;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
WriteChunkBytes(iffh, buffer, strlen(buffer));
|
|
|
|
ami_utf8_free(buffer);
|
2011-04-30 14:54:02 +04:00
|
|
|
}
|
|
|
|
}
|
2008-10-26 02:22:34 +03:00
|
|
|
|
2012-08-03 21:15:16 +04:00
|
|
|
if(space) WriteChunkBytes(iffh," ",1);
|
|
|
|
PopChunk(iffh);
|
|
|
|
} else {
|
|
|
|
PopChunk(iffh);
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-03 21:33:49 +04:00
|
|
|
|
|
|
|
if(!(PushChunk(iffh, 0, ID_UTF8, IFFSIZE_UNKNOWN))) {
|
|
|
|
WriteChunkBytes(iffh, text, length);
|
|
|
|
if(space) WriteChunkBytes(iffh, " ", 1);
|
|
|
|
PopChunk(iffh);
|
|
|
|
} else {
|
|
|
|
PopChunk(iffh);
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-03 21:15:16 +04:00
|
|
|
|
2008-10-26 02:22:34 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gui_commit_clipboard(void)
|
|
|
|
{
|
|
|
|
if(iffh) CloseIFF(iffh);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gui_copy_to_clipboard(struct selection *s)
|
|
|
|
{
|
2012-02-12 21:56:25 +04:00
|
|
|
bool success;
|
|
|
|
|
|
|
|
if(s->defined == false) return false;
|
2010-07-25 00:18:56 +04:00
|
|
|
if(!gui_empty_clipboard()) return false;
|
2008-10-26 02:22:34 +03:00
|
|
|
|
2012-08-03 21:19:54 +04:00
|
|
|
success = selection_copy_to_clipboard(s);
|
2008-10-26 02:22:34 +03:00
|
|
|
|
2012-02-12 21:56:25 +04:00
|
|
|
/* commit regardless, otherwise we leave the clipboard in an unusable state */
|
|
|
|
gui_commit_clipboard();
|
|
|
|
|
|
|
|
return success;
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
|
|
|
|
2011-04-29 22:15:20 +04:00
|
|
|
struct ami_text_selection *ami_selection_to_text(struct gui_window_2 *gwin)
|
|
|
|
{
|
|
|
|
struct ami_text_selection *sel;
|
|
|
|
|
|
|
|
sel = AllocVec(sizeof(struct ami_text_selection),
|
|
|
|
MEMF_PRIVATE | MEMF_CLEAR);
|
|
|
|
|
2011-07-13 17:38:38 +04:00
|
|
|
if(sel) selection_traverse(browser_window_get_selection(gwin->bw), ami_copy_selection, sel);
|
2011-04-29 22:15:20 +04:00
|
|
|
|
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ami_copy_selection(const char *text, size_t length,
|
|
|
|
struct box *box, void *handle, const char *whitespace_text,
|
|
|
|
size_t whitespace_length)
|
|
|
|
{
|
|
|
|
struct ami_text_selection *sel = handle;
|
|
|
|
int len = length;
|
|
|
|
|
|
|
|
if((length + (sel->length)) > (sizeof(sel->text)))
|
|
|
|
len = sizeof(sel->text) - (sel->length);
|
|
|
|
|
|
|
|
if(len <= 0) return false;
|
|
|
|
|
|
|
|
memcpy((sel->text) + (sel->length), text, len);
|
|
|
|
sel->length += len;
|
|
|
|
|
|
|
|
sel->text[sel->length] = '\0';
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-24 23:57:27 +04:00
|
|
|
void ami_drag_selection(struct selection *s)
|
|
|
|
{
|
|
|
|
struct box *text_box;
|
2011-04-29 22:15:20 +04:00
|
|
|
int x;
|
|
|
|
int y;
|
2011-04-30 15:11:34 +04:00
|
|
|
char *utf8text;
|
2011-04-29 22:15:20 +04:00
|
|
|
struct ami_text_selection *sel;
|
2010-10-24 22:07:11 +04:00
|
|
|
struct IFFHandle *old_iffh = iffh;
|
2011-12-02 17:24:40 +04:00
|
|
|
struct gui_window_2 *gwin = ami_window_at_pointer(AMINS_WINDOW);
|
2010-07-24 23:57:27 +04:00
|
|
|
|
2010-07-28 01:41:21 +04:00
|
|
|
if(!gwin)
|
|
|
|
{
|
|
|
|
DisplayBeep(scrn);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = gwin->win->MouseX;
|
|
|
|
y = gwin->win->MouseY;
|
|
|
|
|
2011-07-23 18:06:13 +04:00
|
|
|
if(text_box = ami_text_box_at_point(gwin, (ULONG *)&x, (ULONG *)&y))
|
2010-07-24 23:57:27 +04:00
|
|
|
{
|
2010-10-24 22:07:11 +04:00
|
|
|
iffh = ami_clipboard_init_internal(1);
|
|
|
|
|
2010-07-24 23:57:27 +04:00
|
|
|
if(gui_copy_to_clipboard(s))
|
|
|
|
{
|
2010-07-28 01:41:21 +04:00
|
|
|
browser_window_mouse_click(gwin->bw, BROWSER_MOUSE_PRESS_1, x, y);
|
|
|
|
browser_window_key_press(gwin->bw, KEY_PASTE);
|
2010-07-24 23:57:27 +04:00
|
|
|
}
|
2010-10-24 22:07:11 +04:00
|
|
|
|
|
|
|
ami_clipboard_free_internal(iffh);
|
|
|
|
iffh = old_iffh;
|
2010-07-24 23:57:27 +04:00
|
|
|
}
|
2010-07-28 01:41:21 +04:00
|
|
|
else
|
|
|
|
{
|
2011-04-29 22:15:20 +04:00
|
|
|
x = gwin->win->MouseX;
|
|
|
|
y = gwin->win->MouseY;
|
|
|
|
|
|
|
|
if(ami_gadget_hit(gwin->objects[GID_URL], x, y))
|
|
|
|
{
|
|
|
|
if(sel = ami_selection_to_text(gwin))
|
|
|
|
{
|
2011-04-30 15:11:34 +04:00
|
|
|
utf8text = ami_utf8_easy(sel->text);
|
2011-04-29 22:15:20 +04:00
|
|
|
RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_URL],
|
2011-04-30 15:11:34 +04:00
|
|
|
gwin->win, NULL, STRINGA_TextVal, utf8text, TAG_DONE);
|
2011-04-29 22:15:20 +04:00
|
|
|
FreeVec(sel);
|
2011-04-30 15:11:34 +04:00
|
|
|
ami_utf8_free(utf8text);
|
2011-04-29 22:15:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(ami_gadget_hit(gwin->objects[GID_SEARCHSTRING], x, y))
|
|
|
|
{
|
|
|
|
if(sel = ami_selection_to_text(gwin))
|
|
|
|
{
|
2011-04-30 15:11:34 +04:00
|
|
|
utf8text = ami_utf8_easy(sel->text);
|
2011-04-29 22:15:20 +04:00
|
|
|
RefreshSetGadgetAttrs((struct Gadget *)gwin->objects[GID_SEARCHSTRING],
|
2011-04-30 15:11:34 +04:00
|
|
|
gwin->win, NULL, STRINGA_TextVal, utf8text, TAG_DONE);
|
2011-04-29 22:15:20 +04:00
|
|
|
FreeVec(sel);
|
2011-04-30 15:11:34 +04:00
|
|
|
ami_utf8_free(utf8text);
|
2011-04-29 22:15:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DisplayBeep(scrn);
|
|
|
|
}
|
2010-07-28 01:41:21 +04:00
|
|
|
}
|
2010-07-24 23:57:27 +04:00
|
|
|
}
|
|
|
|
|
2008-10-26 02:22:34 +03:00
|
|
|
bool ami_easy_clipboard(char *text)
|
|
|
|
{
|
2010-07-25 00:18:56 +04:00
|
|
|
if(!gui_empty_clipboard()) return false;
|
|
|
|
if(!gui_add_to_clipboard(text,strlen(text),false)) return false;
|
|
|
|
if(!gui_commit_clipboard()) return false;
|
2008-10-26 02:22:34 +03:00
|
|
|
|
2010-07-25 00:18:56 +04:00
|
|
|
return true;
|
2008-10-26 02:22:34 +03:00
|
|
|
}
|
2009-05-16 18:50:30 +04:00
|
|
|
|
2009-05-16 21:04:28 +04:00
|
|
|
bool ami_easy_clipboard_bitmap(struct bitmap *bitmap)
|
2009-05-16 18:50:30 +04:00
|
|
|
{
|
2009-05-16 21:04:28 +04:00
|
|
|
Object *dto = NULL;
|
2009-05-16 18:50:30 +04:00
|
|
|
|
2009-05-16 21:04:28 +04:00
|
|
|
if(dto = ami_datatype_object_from_bitmap(bitmap))
|
2009-05-16 18:50:30 +04:00
|
|
|
{
|
2009-05-16 21:04:28 +04:00
|
|
|
DoDTMethod(dto,NULL,NULL,DTM_COPY,NULL);
|
|
|
|
DisposeDTObject(dto);
|
2009-05-16 18:50:30 +04:00
|
|
|
}
|
|
|
|
}
|
2009-05-19 11:23:56 +04:00
|
|
|
|
2009-05-19 11:30:00 +04:00
|
|
|
#ifdef WITH_NS_SVG
|
2010-03-28 19:51:05 +04:00
|
|
|
bool ami_easy_clipboard_svg(struct hlcache_handle *c)
|
2009-05-19 11:23:56 +04:00
|
|
|
{
|
2011-07-23 18:06:13 +04:00
|
|
|
const char *source_data;
|
2010-03-28 19:51:05 +04:00
|
|
|
ULONG source_size;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if(ami_mime_compare(c, "svg") == false) return false;
|
2010-03-28 19:51:05 +04:00
|
|
|
if((source_data = content_get_source_data(c, &source_size)) == NULL) return false;
|
2009-05-19 11:23:56 +04:00
|
|
|
|
|
|
|
if(!(OpenIFF(iffh,IFFF_WRITE)))
|
|
|
|
{
|
2011-12-04 18:55:23 +04:00
|
|
|
ami_svg_to_dr2d(iffh, source_data, source_size, nsurl_access(hlcache_handle_get_url(c)));
|
2009-05-19 11:23:56 +04:00
|
|
|
CloseIFF(iffh);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-19 11:30:00 +04:00
|
|
|
#endif
|