2010-10-30 15:21:38 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
|
|
|
*
|
|
|
|
* 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 <string.h>
|
|
|
|
|
|
|
|
#include <proto/wb.h>
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <proto/dos.h>
|
|
|
|
#include <proto/intuition.h>
|
|
|
|
#include <proto/utility.h>
|
|
|
|
#include <proto/icon.h>
|
|
|
|
#include <proto/layers.h>
|
|
|
|
|
2011-01-07 02:17:17 +03:00
|
|
|
#ifdef __amigaos4__
|
2010-10-30 15:21:38 +04:00
|
|
|
#include <graphics/blitattr.h>
|
2011-01-07 02:17:17 +03:00
|
|
|
#endif
|
2010-10-30 15:21:38 +04:00
|
|
|
#include <workbench/icon.h>
|
|
|
|
|
2011-10-15 19:27:56 +04:00
|
|
|
#include "amiga/bitmap.h"
|
2011-03-26 13:33:58 +03:00
|
|
|
#include "amiga/clipboard.h"
|
2010-10-30 15:21:38 +04:00
|
|
|
#include "amiga/download.h"
|
|
|
|
#include "amiga/drag.h"
|
2011-10-15 19:27:56 +04:00
|
|
|
#include "amiga/file.h"
|
2010-10-30 15:21:38 +04:00
|
|
|
#include "amiga/filetype.h"
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2010-10-30 15:21:38 +04:00
|
|
|
#include "amiga/theme.h"
|
|
|
|
|
|
|
|
#include "utils/errors.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
|
|
|
struct Window *drag_icon = NULL;
|
|
|
|
ULONG drag_icon_width;
|
|
|
|
ULONG drag_icon_height;
|
|
|
|
BOOL drag_in_progress = FALSE;
|
|
|
|
|
2014-01-14 02:54:19 +04:00
|
|
|
void gui_drag_save_object(struct gui_window *g, hlcache_handle *c,
|
|
|
|
gui_save_type type)
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
2012-03-22 13:34:34 +04:00
|
|
|
const char *filetype = NULL;
|
2010-10-30 15:21:38 +04:00
|
|
|
|
2014-08-25 23:13:59 +04:00
|
|
|
/* Check we are running on Workbench */
|
|
|
|
if(nsoption_charp(pubscreen_name) == NULL) return;
|
2013-06-01 02:25:05 +04:00
|
|
|
if(strcmp(nsoption_charp(pubscreen_name), "Workbench")) return;
|
2010-10-30 15:21:38 +04:00
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GUI_SAVE_OBJECT_ORIG: // object
|
|
|
|
case GUI_SAVE_SOURCE:
|
2011-06-16 01:53:49 +04:00
|
|
|
filetype = ami_mime_content_to_filetype(c);
|
2010-10-30 15:21:38 +04:00
|
|
|
break;
|
|
|
|
case GUI_SAVE_COMPLETE:
|
|
|
|
filetype = "drawer";
|
|
|
|
break;
|
|
|
|
case GUI_SAVE_OBJECT_NATIVE:
|
|
|
|
#ifdef WITH_NS_SVG
|
2011-05-07 00:40:09 +04:00
|
|
|
if(ami_mime_compare(c, "svg") == true)
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
|
|
|
filetype = "dr2d";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
filetype = "ilbm";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ami_drag_icon_show(g->shared->win, filetype);
|
|
|
|
|
|
|
|
drag_save_data = c;
|
|
|
|
drag_save_gui = g;
|
|
|
|
drag_save = type;
|
|
|
|
}
|
|
|
|
|
2013-05-10 14:54:26 +04:00
|
|
|
void gui_drag_save_selection(struct gui_window *g, const char *selection)
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
|
|
|
ami_drag_icon_show(g->shared->win, "ascii");
|
|
|
|
|
|
|
|
ami_autoscroll = TRUE;
|
2013-02-22 23:02:58 +04:00
|
|
|
drag_save_data = g;
|
2010-10-30 15:21:38 +04:00
|
|
|
drag_save = GUI_SAVE_TEXT_SELECTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ami_drag_save(struct Window *win)
|
|
|
|
{
|
2014-04-05 23:18:26 +04:00
|
|
|
ULONG which = WBO_NONE, type;
|
|
|
|
char path[1025], dpath[1025];
|
2010-10-30 15:21:38 +04:00
|
|
|
ULONG source_size;
|
|
|
|
|
|
|
|
ami_drag_icon_close(NULL);
|
|
|
|
ami_autoscroll = FALSE;
|
|
|
|
|
2013-06-01 02:25:05 +04:00
|
|
|
if(nsoption_charp(pubscreen_name) && (strcmp(nsoption_charp(pubscreen_name),"Workbench") == 0))
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
|
|
|
which = WhichWorkbenchObject(NULL,scrn->MouseX,scrn->MouseY,
|
|
|
|
WBOBJA_Type,&type,
|
|
|
|
WBOBJA_FullPath,&path,
|
|
|
|
WBOBJA_FullPathSize,1024,
|
|
|
|
WBOBJA_DrawerPath,&dpath,
|
|
|
|
WBOBJA_DrawerPathSize,1024,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if((which == WBO_DRAWER) || ((which == WBO_ICON) && (type > WBDRAWER)))
|
|
|
|
{
|
|
|
|
strcpy(path,dpath);
|
|
|
|
}
|
|
|
|
else if(which == WBO_NONE)
|
|
|
|
{
|
|
|
|
if(drag_save == GUI_SAVE_TEXT_SELECTION)
|
2013-02-22 23:02:58 +04:00
|
|
|
ami_drag_selection((struct gui_window *)drag_save_data);
|
2010-10-30 15:21:38 +04:00
|
|
|
else DisplayBeep(scrn);
|
|
|
|
|
|
|
|
drag_save = 0;
|
|
|
|
drag_save_data = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(path[0] == '\0')
|
|
|
|
{
|
|
|
|
DisplayBeep(scrn);
|
|
|
|
drag_save = 0;
|
|
|
|
drag_save_data = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-06 04:21:15 +04:00
|
|
|
ami_update_pointer(win, GUI_POINTER_WAIT);
|
2010-10-30 15:21:38 +04:00
|
|
|
|
|
|
|
switch(drag_save)
|
|
|
|
{
|
|
|
|
case GUI_SAVE_OBJECT_ORIG: // object
|
|
|
|
case GUI_SAVE_SOURCE:
|
|
|
|
{
|
|
|
|
struct hlcache_handle *c = drag_save_data;
|
|
|
|
BPTR fh = 0;
|
|
|
|
AddPart(path, content_get_title(c), 1024);
|
|
|
|
|
2011-10-23 17:15:44 +04:00
|
|
|
ami_file_save(AMINS_SAVE_SOURCE, path, win, c, NULL, NULL);
|
2010-10-30 15:21:38 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_SAVE_TEXT_SELECTION: // selection
|
2012-01-02 16:03:45 +04:00
|
|
|
AddPart(path,"netsurf_text_selection",1024);
|
2013-02-23 01:03:52 +04:00
|
|
|
struct gui_window *g = (struct gui_window *) drag_save_data;
|
|
|
|
ami_file_save(AMINS_SAVE_SELECTION, path, win, NULL, NULL, g->shared->bw);
|
2010-10-30 15:21:38 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_SAVE_COMPLETE:
|
|
|
|
{
|
|
|
|
struct hlcache_handle *c = drag_save_data;
|
|
|
|
BPTR lock = 0;
|
|
|
|
|
|
|
|
AddPart(path, content_get_title(c), 1024);
|
2011-03-26 13:33:58 +03:00
|
|
|
|
2011-10-23 17:15:44 +04:00
|
|
|
ami_file_save(AMINS_SAVE_COMPLETE, path, win, c, drag_save_gui->favicon, NULL);
|
2010-10-30 15:21:38 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_SAVE_OBJECT_NATIVE:
|
|
|
|
{
|
|
|
|
hlcache_handle *c = drag_save_data;
|
|
|
|
AddPart(path, content_get_title(c), 1024);
|
2011-10-15 19:27:56 +04:00
|
|
|
|
2011-10-23 17:15:44 +04:00
|
|
|
ami_file_save(AMINS_SAVE_IFF, path, win, c, NULL, NULL);
|
2010-10-30 15:21:38 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LOG(("Unsupported drag save operation %ld",drag_save));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
drag_save = 0;
|
|
|
|
drag_save_data = NULL;
|
2013-01-06 04:21:15 +04:00
|
|
|
|
|
|
|
ami_update_pointer(win, GUI_POINTER_DEFAULT);
|
2010-10-30 15:21:38 +04:00
|
|
|
}
|
|
|
|
|
2011-07-23 18:06:13 +04:00
|
|
|
void ami_drag_icon_show(struct Window *win, const char *type)
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
|
|
|
struct DiskObject *dobj = NULL;
|
|
|
|
ULONG width, height;
|
2014-04-05 23:18:26 +04:00
|
|
|
int err;
|
2010-10-30 15:21:38 +04:00
|
|
|
int deftype = WBPROJECT;
|
|
|
|
|
|
|
|
drag_in_progress = TRUE;
|
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
if(nsoption_bool(drag_save_icons) == false)
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
2013-01-06 04:21:15 +04:00
|
|
|
ami_update_pointer(win, AMI_GUI_POINTER_DRAG);
|
2010-10-30 15:21:38 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-06 04:21:15 +04:00
|
|
|
ami_update_pointer(win, GUI_POINTER_DEFAULT);
|
2010-10-30 15:21:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!strcmp(type, "drawer")) deftype = WBDRAWER;
|
|
|
|
|
|
|
|
dobj = GetIconTags(NULL, ICONGETA_GetDefaultName, type,
|
|
|
|
ICONGETA_GetDefaultType, deftype,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
err = IconControl(dobj,
|
|
|
|
ICONCTRLA_GetWidth,&width,
|
|
|
|
ICONCTRLA_GetHeight,&height,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
drag_icon_width = width;
|
|
|
|
drag_icon_height = height;
|
|
|
|
|
|
|
|
drag_icon = OpenWindowTags(NULL,
|
|
|
|
WA_Left, scrn->MouseX - (width/2),
|
|
|
|
WA_Top, scrn->MouseY - (height/2),
|
|
|
|
WA_Width, width,
|
|
|
|
WA_Height, height,
|
|
|
|
WA_PubScreen, scrn,
|
|
|
|
WA_Borderless, TRUE,
|
|
|
|
WA_ToolBox, TRUE,
|
|
|
|
WA_StayTop, TRUE,
|
|
|
|
WA_Opaqueness, 128,
|
|
|
|
WA_OverrideOpaqueness, TRUE,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
/* probably need layouticon and drawinfo stuff too */
|
|
|
|
|
|
|
|
DrawIconState(drag_icon->RPort, dobj, NULL, 0, 0, IDS_NORMAL,
|
|
|
|
ICONDRAWA_Frameless, TRUE,
|
|
|
|
ICONDRAWA_Borderless, TRUE,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ami_drag_icon_move(void)
|
|
|
|
{
|
|
|
|
if(drag_icon == NULL) return;
|
|
|
|
|
|
|
|
ChangeWindowBox(drag_icon, scrn->MouseX - (drag_icon_width / 2),
|
|
|
|
scrn->MouseY - (drag_icon_height / 2),
|
|
|
|
drag_icon_width, drag_icon_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the drag icon (invisible) window if it is open
|
|
|
|
*
|
|
|
|
* \param win pointer to window to clear drag pointer
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ami_drag_icon_close(struct Window *win)
|
|
|
|
{
|
|
|
|
if(drag_icon) CloseWindow(drag_icon);
|
2013-01-06 04:21:15 +04:00
|
|
|
if(win) ami_update_pointer(win, GUI_POINTER_DEFAULT);
|
2010-10-30 15:21:38 +04:00
|
|
|
drag_icon = NULL;
|
|
|
|
drag_in_progress = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ami_drag_in_progress(void)
|
|
|
|
{
|
|
|
|
return drag_in_progress;
|
|
|
|
}
|
|
|
|
|
2011-12-02 17:24:40 +04:00
|
|
|
void *ami_find_gwin_by_id(struct Window *win, int type)
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
|
|
|
struct nsObject *node, *nnode;
|
|
|
|
struct gui_window_2 *gwin;
|
|
|
|
|
|
|
|
if(!IsMinListEmpty(window_list))
|
|
|
|
{
|
|
|
|
node = (struct nsObject *)GetHead((struct List *)window_list);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nnode=(struct nsObject *)GetSucc((struct Node *)node);
|
|
|
|
|
2011-12-02 17:24:40 +04:00
|
|
|
if(node->Type == type)
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
|
|
|
gwin = node->objstruct;
|
|
|
|
if(win == gwin->win) return gwin;
|
|
|
|
}
|
|
|
|
} while(node = nnode);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-02 17:24:40 +04:00
|
|
|
void *ami_window_at_pointer(int type)
|
2010-10-30 15:21:38 +04:00
|
|
|
{
|
|
|
|
struct Layer *layer;
|
|
|
|
|
|
|
|
LockLayerInfo(&scrn->LayerInfo);
|
|
|
|
|
|
|
|
layer = WhichLayer(&scrn->LayerInfo, scrn->MouseX, scrn->MouseY);
|
|
|
|
|
|
|
|
UnlockLayerInfo(&scrn->LayerInfo);
|
|
|
|
|
2011-12-02 17:24:40 +04:00
|
|
|
if(layer) return ami_find_gwin_by_id(layer->Window, type);
|
2011-04-29 22:15:20 +04:00
|
|
|
else return NULL;
|
2010-10-30 15:21:38 +04:00
|
|
|
}
|