NetSurf
drag.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 Chris Young <chris@unsatisfactorysoftware.co.uk>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifdef __amigaos4__
19#include <string.h>
20
21#include <proto/wb.h>
22#include <proto/exec.h>
23#include <proto/dos.h>
24#include <proto/intuition.h>
25#include <proto/utility.h>
26#include <proto/icon.h>
27
28#include <graphics/blitattr.h>
29#include <workbench/icon.h>
30
31#include "utils/errors.h"
32#include "utils/log.h"
33#include "utils/messages.h"
34#include "utils/utils.h"
35#include "utils/nsoption.h"
36#include "netsurf/mouse.h"
37#include "netsurf/content.h"
38
39#include "amiga/bitmap.h"
40#include "amiga/clipboard.h"
41#include "amiga/download.h"
42#include "amiga/drag.h"
43#include "amiga/file.h"
44#include "amiga/filetype.h"
45#include "amiga/gui.h"
46#include "amiga/theme.h"
47
48static void *drag_save_data;
49static int drag_save;
50static struct gui_window *drag_save_gui;
51static struct Window *drag_icon = NULL;
52static ULONG drag_icon_width;
53static ULONG drag_icon_height;
54static BOOL drag_in_progress = FALSE;
55static bool ami_autoscroll = false;
56
57void gui_drag_save_object(struct gui_window *g, struct hlcache_handle *c,
59{
60 const char *filetype = NULL;
61
62 /* Check we are running on Workbench */
63 if(nsoption_charp(pubscreen_name) == NULL) return;
64 if(strcmp(nsoption_charp(pubscreen_name), "Workbench")) return;
65
66 switch(type) {
67 case GUI_SAVE_OBJECT_ORIG: // object
68 case GUI_SAVE_SOURCE:
69 filetype = ami_mime_content_to_filetype(c);
70 break;
72 filetype = "drawer";
73 break;
75#ifdef WITH_NS_SVG
76 if(ami_mime_compare(c, "svg") == true)
77 {
78 filetype = "dr2d";
79 }
80 else
81#endif
82 {
83 filetype = "ilbm";
84 }
85 break;
86
87 default:
88 break;
89 }
90
92
93 drag_save_data = c;
94 drag_save_gui = g;
95 drag_save = type;
96}
97
98void gui_drag_save_selection(struct gui_window *g, const char *selection)
99{
101
102 ami_autoscroll = true;
103 drag_save_data = g;
104 drag_save = GUI_SAVE_TEXT_SELECTION;
105}
106
107void ami_drag_save(struct Window *win)
108{
109 ULONG which = WBO_NONE, type;
110 char path[1025], dpath[1025];
111 struct Screen *scrn = ami_gui_get_screen();
112
113 path[0] = 0; /* ensure path is terminated */
114
116 ami_autoscroll = true;
117
118 if(nsoption_charp(pubscreen_name) && (strcmp(nsoption_charp(pubscreen_name),"Workbench") == 0))
119 {
120 which = WhichWorkbenchObject(NULL,scrn->MouseX,scrn->MouseY,
121 WBOBJA_Type,&type,
122 WBOBJA_FullPath,&path,
123 WBOBJA_FullPathSize,1024,
124 WBOBJA_DrawerPath,&dpath,
125 WBOBJA_DrawerPathSize,1024,
126 TAG_DONE);
127 }
128
129 if((which == WBO_DRAWER) || ((which == WBO_ICON) && (type > WBDRAWER)))
130 {
131 strcpy(path,dpath);
132 }
133 else if(which == WBO_NONE)
134 {
135 if(drag_save == GUI_SAVE_TEXT_SELECTION)
136 ami_drag_selection((struct gui_window *)drag_save_data);
137 else ami_gui_beep();
138
139 drag_save = 0;
140 drag_save_data = NULL;
141 return;
142 }
143
144 if(path[0] == '\0')
145 {
146 ami_gui_beep();
147 drag_save = 0;
148 drag_save_data = NULL;
149 return;
150 }
151
153
154 switch(drag_save)
155 {
156 case GUI_SAVE_OBJECT_ORIG: // object
157 case GUI_SAVE_SOURCE:
158 {
159 struct hlcache_handle *c = drag_save_data;
160
161 AddPart(path, content_get_title(c), 1024);
162 ami_file_save(AMINS_SAVE_SOURCE, path, win, c, NULL, NULL);
163 }
164 break;
165
166 case GUI_SAVE_TEXT_SELECTION: // selection
167 AddPart(path,"netsurf_text_selection",1024);
168 struct gui_window *g = (struct gui_window *) drag_save_data;
170 break;
171
173 {
174 struct hlcache_handle *c = drag_save_data;
175
176 AddPart(path, content_get_title(c), 1024);
177 ami_file_save(AMINS_SAVE_COMPLETE, path, win, c, ami_gui_get_favicon(drag_save_gui), NULL);
178 }
179 break;
180
182 {
183 struct hlcache_handle *c = drag_save_data;
184 AddPart(path, content_get_title(c), 1024);
185
186 ami_file_save(AMINS_SAVE_IFF, path, win, c, NULL, NULL);
187 }
188 break;
189
190 default:
191 NSLOG(netsurf, INFO,
192 "Unsupported drag save operation %d", drag_save);
193 break;
194 }
195
196 drag_save = 0;
197 drag_save_data = NULL;
198
200}
201
202void ami_drag_icon_show(struct Window *win, const char *type)
203{
204 struct DiskObject *dobj = NULL;
205 ULONG width, height;
206 int deftype = WBPROJECT;
207 struct Screen *scrn = ami_gui_get_screen();
208 drag_in_progress = TRUE;
209
210 if(nsoption_bool(drag_save_icons) == false)
211 {
213 return;
214 }
215 else
216 {
218 }
219
220 if(!strcmp(type, "drawer")) deftype = WBDRAWER;
221
222 dobj = GetIconTags(NULL, ICONGETA_GetDefaultName, type,
223 ICONGETA_GetDefaultType, deftype,
224 TAG_DONE);
225
226 IconControl(dobj,
227 ICONCTRLA_GetWidth,&width,
228 ICONCTRLA_GetHeight,&height,
229 TAG_DONE);
230
231 drag_icon_width = width;
232 drag_icon_height = height;
233
234 drag_icon = OpenWindowTags(NULL,
235 WA_Left, scrn->MouseX - (width/2),
236 WA_Top, scrn->MouseY - (height/2),
237 WA_Width, width,
238 WA_Height, height,
239 WA_PubScreen, scrn,
240 WA_Borderless, TRUE,
241 WA_ToolBox, TRUE,
242 WA_StayTop, TRUE,
243 WA_Opaqueness, 128,
244 WA_OverrideOpaqueness, TRUE,
245 TAG_DONE);
246
247/* probably need layouticon and drawinfo stuff too */
248
249 DrawIconState(drag_icon->RPort, dobj, NULL, 0, 0, IDS_NORMAL,
250 ICONDRAWA_Frameless, TRUE,
251 ICONDRAWA_Borderless, TRUE,
252 TAG_DONE);
253}
254
255bool ami_drag_icon_move(void)
256{
257 if(drag_icon == NULL) return FALSE;
258 struct Screen *scrn = ami_gui_get_screen();
259
260 ChangeWindowBox(drag_icon, scrn->MouseX - (drag_icon_width / 2),
261 scrn->MouseY - (drag_icon_height / 2),
262 drag_icon_width, drag_icon_height);
263
264 return ami_autoscroll;
265}
266
267/**
268 * Close the drag icon (invisible) window if it is open
269 *
270 * \param win pointer to window to clear drag pointer
271 */
272
273void ami_drag_icon_close(struct Window *win)
274{
275 if(drag_icon) CloseWindow(drag_icon);
277 drag_icon = NULL;
278 drag_in_progress = FALSE;
279}
280
281BOOL ami_drag_in_progress(void)
282{
283 return drag_in_progress;
284}
285
286bool ami_drag_has_data(void)
287{
288 if(drag_save_data != NULL) return true;
289 else return false;
290}
291
292#else
293#include <stddef.h>
294
295#include "utils/errors.h"
296#include "amiga/drag.h"
297
300{
301}
302
303void gui_drag_save_selection(struct gui_window *g, const char *selection)
304{
305}
306
307void ami_drag_save(struct Window *win)
308{
309}
310
311void ami_drag_icon_show(struct Window *win, const char *type)
312{
313}
314
315void ami_drag_icon_close(struct Window *win)
316{
317}
318
320{
321 return false;
322}
323
325{
326 return FALSE;
327}
328
330{
331 return false;
332}
333#endif
334
void ami_drag_selection(struct gui_window *g)
Definition: clipboard.c:266
bool ami_mime_compare(struct hlcache_handle *c, const char *type)
Compare the MIME type of an hlcache_handle to a DefIcons type.
Definition: filetype.c:614
const char * ami_mime_content_to_filetype(struct hlcache_handle *c)
Definition: filetype.c:523
struct Window * ami_gui_get_window(struct gui_window *gw)
Get window from gui_window.
Definition: gui.c:577
struct Screen * ami_gui_get_screen(void)
Get a pointer to the screen NetSurf is running on.
Definition: gui.c:404
static struct Screen * scrn
Definition: gui.c:327
void ami_gui_beep(void)
Beep.
Definition: gui.c:415
struct hlcache_handle * ami_gui_get_favicon(struct gui_window *gw)
Get favicon from gui_window.
Definition: gui.c:481
struct browser_window * ami_gui_get_browser_window(struct gui_window *gw)
Get browser window from gui_window.
Definition: gui.c:420
void ami_update_pointer(struct Window *win, gui_pointer_shape shape)
Definition: theme.c:221
bool ami_drag_has_data(void)
Definition: drag.c:329
void gui_drag_save_selection(struct gui_window *g, const char *selection)
Definition: drag.c:303
void ami_drag_icon_show(struct Window *win, const char *type)
Definition: drag.c:311
void ami_drag_save(struct Window *win)
Definition: drag.c:307
bool ami_drag_icon_move(void)
Definition: drag.c:319
void gui_drag_save_object(struct gui_window *g, struct hlcache_handle *c, gui_save_type type)
Definition: drag.c:298
BOOL ami_drag_in_progress(void)
Definition: drag.c:324
void ami_drag_icon_close(struct Window *win)
Definition: drag.c:315
Error codes.
const char * type
Definition: filetype.cpp:44
void ami_file_save(int type, char *fname, struct Window *win, struct hlcache_handle *object, struct hlcache_handle *favicon, struct browser_window *bw)
Definition: file.c:147
@ AMINS_SAVE_IFF
Definition: file.h:32
@ AMINS_SAVE_SELECTION
Definition: file.h:33
@ AMINS_SAVE_SOURCE
Definition: file.h:28
@ AMINS_SAVE_COMPLETE
Definition: file.h:30
#define AMI_GUI_POINTER_DRAG
Definition: theme.h:28
Public content interface.
const char * content_get_title(struct hlcache_handle *h)
Retrieve title associated with content.
Definition: content.c:1106
Core mouse and pointer states.
@ GUI_POINTER_WAIT
Definition: mouse.h:127
@ GUI_POINTER_DEFAULT
Definition: mouse.h:113
gui_save_type
Definition: window.h:39
@ GUI_SAVE_OBJECT_ORIG
Definition: window.h:45
@ GUI_SAVE_SOURCE
Definition: window.h:40
@ GUI_SAVE_TEXT_SELECTION
Definition: window.h:52
@ GUI_SAVE_OBJECT_NATIVE
Definition: window.h:46
@ GUI_SAVE_COMPLETE
Definition: window.h:44
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
Localised message support (interface).
#define WA_ToolBox
Definition: os3support.h:90
int width
Definition: gui.c:160
int height
Definition: gui.c:161
Interface to utility string handling.
first entry in window list
Definition: gui.c:297
High-level cache handle.
Definition: hlcache.c:66
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:304
Interface to a number of general purpose functionality.
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plot.c:821