1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/* Copyright 1997 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/***************************************************/
/* File : SaveObject.c */
/* */
/* Purpose: Handle the Save Object dialogue */
/* (actual object saving is done in */
/* Save.c). */
/* */
/* Author : A.D.Hodgkinson */
/* */
/* History: 03-Sep-97: Created. */
/* */
/* 05-Sep-97: Split so bulk became the */
/* SaveFile source, and the */
/* small fetch saving stayed */
/* in here. */
/***************************************************/
#include <stdlib.h>
#include <string.h>
#include "swis.h"
#include "HTMLLib.h" /* HTML library API, Which will include html2_ext.h, tags.h and struct.h */
#include "wimp.h"
#include "wimplib.h"
#include "event.h"
#include "toolbox.h"
#include "window.h"
#include "gadgets.h"
#include "svcprint.h"
#include "Global.h"
#include "Utils.h"
#include "Browser.h"
#include "Fetch.h" /* (For ISLINK macro) */
#include "Protocols.h"
#include "Save.h"
#include "SaveFile.h"
#include "Windows.h"
#include "SaveObject.h"
/* Static function prototypes */
static int saveobject_drag_ended (int eventcode, ToolboxEvent * event, IdBlock * idb, browser_data * handle);
static int saveobject_ok (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
static int saveobject_cancel (int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle);
/*************************************************/
/* saveobject_open_for() */
/* */
/* Creates and opens a Save Object dialogue for */
/* a given browser, opening near the pointer. */
/* */
/* Parameters: Pointer to a browser_data struct */
/* which is the ancestor of the */
/* dialogue. */
/*************************************************/
_kernel_oserror * saveobject_open_for(browser_data * b)
{
_kernel_oserror * e;
ObjectId id;
/* Create and show the object */
RetError(toolbox_create_object(0,
"SaveObject",
&id));
/* Remember the ID */
b->save_dbox = id;
/* Show it - everything else is done when the ToBeShown */
/* event comes in. */
RetError(toolbox_show_object(0,
id,
Toolbox_ShowObject_Centre,
NULL,
b->self_id,
-1));
return NULL;
}
/*************************************************/
/* saveobject_to_be_shown() */
/* */
/* Fills in the Save Object dialogue prior to */
/* being shown. */
/* */
/* Parameters are as standard for a Toolbox */
/* event handler. */
/*************************************************/
int saveobject_to_be_shown(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
char text[Limits_OS_Pathname];
browser_data * b;
/* Process the writable icon text */
ChkError(windows_process_component_text(idb->self_id, SaveObjectWrit, text, sizeof(text), 0, 1));
/* Where did we come from? */
ChkError(toolbox_get_client_handle(0, idb->ancestor_id, (void *) &b));
#ifndef TRACE
if (!b || (b && !is_known_browser(b)) || (b && !b->source)) return 0;
#else
if (!b || (b && !is_known_browser(b)) || (b && !b->source))
{
erb.errnum = 0;
sprintf(erb.errmess,
"Save dialogue origin of object is inappropriate; browser is %p, source NULL, in saveobject_to_be_shown",
b);
show_error_ret(&erb);
return 0;
}
#endif
/* Set an appropriate path/leafname */
ChkError(savefile_set_leafname_from_url(idb->self_id, SaveObjectWrit, browser_fetch_url(b)));
/* Set the draggable sprite */
ChkError(savefile_set_filetype(idb->self_id, SaveObjectDrag, b->save_type));
/* Install required event handlers */
ChkError(event_register_toolbox_handler(idb->self_id, Draggable_DragEnded, (ToolboxEventHandler *) saveobject_drag_ended, b));
ChkError(event_register_toolbox_handler(idb->self_id, ESaveObjectOK, saveobject_ok, b));
ChkError(event_register_toolbox_handler(idb->self_id, ESaveObjectCancel, saveobject_cancel, b));
return 1;
}
/*************************************************/
/* saveobject_drag_ended() */
/* */
/* Handle Draggable_DragEnded events from the */
/* Save Object dialogue draggable sprite gadget. */
/* */
/* Parameters are as standard for a Toolbox */
/* event handler. */
/*************************************************/
static int saveobject_drag_ended(int eventcode, ToolboxEvent * event, IdBlock * idb, browser_data * handle)
{
DraggableDragEndedEvent * drag = (DraggableDragEndedEvent *) event;
WimpGetPointerInfoBlock info;
int window_handle;
char path[Limits_OS_Pathname];
char * leaf;
/* If the user dragged back to the save dialogue, do nothing */
ChkError(window_get_wimp_handle(0,
idb->self_id,
&window_handle));
if (window_handle == drag->window_handle) return 1;
/* Get the pathname from the Save Object dialogue. */
ChkError(writablefield_get_value(0,
idb->self_id,
SaveObjectWrit,
path,
sizeof(path),
NULL));
path[sizeof(path) - 1] = 0;
/* Point to the leafname component */
leaf = strrchr(path, '.');
if (!leaf) leaf = path;
else leaf ++;
/* Send out the DataSave message */
info.x = drag->x;
info.y = drag->y;
info.window_handle = drag->window_handle;
info.icon_handle = drag->icon_handle;
ChkError(protocols_atats_send_data_save(handle,
NULL,
leaf,
save_object_size(handle),
handle->save_type,
protocols_saving_object,
&info));
/* Close the save dialogue (but don't delete it yet) */
ChkError(toolbox_hide_object(0, handle->save_dbox));
return 1;
}
/*************************************************/
/* saveobject_ok() */
/* */
/* Handles clicks on the 'OK' button in the */
/* Save Object dialogue. */
/* */
/* Parameters are as standard for a Toolbox */
/* event handler. */
/*************************************************/
static int saveobject_ok(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
return 1;
}
/*************************************************/
/* saveobject_cancel() */
/* */
/* Handles clicks on the 'Cancel' button in the */
/* Save Object dialogue */
/* */
/* Parameters are as standard for a Toolbox */
/* event handler. */
/*************************************************/
static int saveobject_cancel(int eventcode, ToolboxEvent * event, IdBlock * idb, void * handle)
{
browser_data * b;
/* We don't do anything sophisticated, like */
/* restoring previous options here, as the */
/* dialogue is too simple for it to be */
/* worthwhile. */
ChkError(toolbox_get_client_handle(0, idb->ancestor_id, (void *) &b));
/* If we were fetching, stop the fetch */
if (b && is_known_browser(b) && b->savelink) fetch_stop(b, 0);
/* Close the dialogue */
ChkError(saveobject_close(b));
return 1;
}
/*************************************************/
/* saveobject_close() */
/* */
/* If the Save Object dialogue is opened, this */
/* will close it, deregistering any associated */
/* event handlers. The dialogue is deleted. */
/* */
/* Parameters: Pointer to a browser_data struct */
/* relevant to the dialogue. */
/*************************************************/
_kernel_oserror * saveobject_close(browser_data * b)
{
_kernel_oserror * e;
if (!b->save_dbox) return NULL;
/* Get rid of any event handlers */
RetError(event_deregister_toolbox_handlers_for_object(b->save_dbox));
/* Delete the dialogue */
e = toolbox_delete_object(0, b->save_dbox);
b->save_dbox = 0;
return e;
}