~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

1 by Daniel Holbach
Import upstream version 2.2.9
1
/*
1.1.5 by Daniel Holbach
Import upstream version 2.3.18
2
 * This is a plug-in for GIMP.
1 by Daniel Holbach
Import upstream version 2.2.9
3
 *
4
 * Generates clickable image maps.
5
 *
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
6
 * Copyright (C) 1998-2005 Maurits Rijk  m.rijk@chello.nl
1 by Daniel Holbach
Import upstream version 2.2.9
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 2 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
 *
22
 */
23
24
#include "config.h"
25
26
#include <gtk/gtk.h>
27
28
#include "imap_commands.h"
29
#include "imap_default_dialog.h"
30
#include "imap_grid.h"
31
#include "imap_main.h"
32
#include "imap_object.h"
33
#include "imap_string.h"
34
35
typedef struct {
36
   ObjectListCallbackFunc_t func;
37
   gpointer data;
38
} ObjectListCB_t;
39
40
static ObjectList_t *_paste_buffer;
41
42
static gpointer
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
43
object_list_callback_add(ObjectListCallback_t *list,
1 by Daniel Holbach
Import upstream version 2.2.9
44
			 ObjectListCallbackFunc_t func, gpointer data)
45
{
46
   ObjectListCB_t *cb = g_new(ObjectListCB_t, 1);
47
   cb->func = func;
48
   cb->data = data;
49
   list->list = g_list_append(list->list, cb);
50
   return cb;
51
}
52
53
static void
54
object_list_callback_remove(ObjectListCallback_t *list, gpointer id)
55
{
56
   list->list = g_list_remove(list->list, id);
57
}
58
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
59
static void
1 by Daniel Holbach
Import upstream version 2.2.9
60
object_list_callback_call(ObjectListCallback_t *list, Object_t *obj)
61
{
62
   GList *p;
63
   for (p = list->list; p; p = p->next) {
64
      ObjectListCB_t *cb = (ObjectListCB_t*) p->data;
65
      cb->func(obj, cb->data);
66
   }
67
}
68
69
gpointer
70
object_list_add_changed_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
71
			   gpointer data)
72
{
73
   return object_list_callback_add(&list->changed_cb, func, data);
74
}
75
76
gpointer
77
object_list_add_update_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
78
			  gpointer data)
79
{
80
   return object_list_callback_add(&list->update_cb, func, data);
81
}
82
83
gpointer
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
84
object_list_add_add_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
1 by Daniel Holbach
Import upstream version 2.2.9
85
		       gpointer data)
86
{
87
   return object_list_callback_add(&list->add_cb, func, data);
88
}
89
90
gpointer
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
91
object_list_add_remove_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
1 by Daniel Holbach
Import upstream version 2.2.9
92
			  gpointer data)
93
{
94
   return object_list_callback_add(&list->remove_cb, func, data);
95
}
96
97
gpointer
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
98
object_list_add_select_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
1 by Daniel Holbach
Import upstream version 2.2.9
99
			  gpointer data)
100
{
101
   return object_list_callback_add(&list->select_cb, func, data);
102
}
103
104
gpointer
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
105
object_list_add_move_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
1 by Daniel Holbach
Import upstream version 2.2.9
106
			gpointer data)
107
{
108
   return object_list_callback_add(&list->move_cb, func, data);
109
}
110
111
gpointer
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
112
object_list_add_geometry_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
1 by Daniel Holbach
Import upstream version 2.2.9
113
			    gpointer data)
114
{
115
   return object_list_callback_add(&list->geometry_cb, func, data);
116
}
117
118
gpointer
119
paste_buffer_add_add_cb(ObjectListCallbackFunc_t func, gpointer data)
120
{
121
   if (!_paste_buffer)
122
      _paste_buffer = make_object_list();
123
   return object_list_callback_add(&_paste_buffer->add_cb, func, data);
124
}
125
126
gpointer
127
paste_buffer_add_remove_cb(ObjectListCallbackFunc_t func, gpointer data)
128
{
129
   if (!_paste_buffer)
130
      _paste_buffer = make_object_list();
131
   return object_list_callback_add(&_paste_buffer->remove_cb, func, data);
132
}
133
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
134
void
1 by Daniel Holbach
Import upstream version 2.2.9
135
object_list_remove_add_cb(ObjectList_t *list, gpointer id)
136
{
137
   object_list_callback_remove(&list->add_cb, id);
138
}
139
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
140
void
1 by Daniel Holbach
Import upstream version 2.2.9
141
object_list_remove_select_cb(ObjectList_t *list, gpointer id)
142
{
143
   object_list_callback_remove(&list->select_cb, id);
144
}
145
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
146
void
1 by Daniel Holbach
Import upstream version 2.2.9
147
object_list_remove_remove_cb(ObjectList_t *list, gpointer id)
148
{
149
   object_list_callback_remove(&list->remove_cb, id);
150
}
151
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
152
void
1 by Daniel Holbach
Import upstream version 2.2.9
153
object_list_remove_move_cb(ObjectList_t *list, gpointer id)
154
{
155
   object_list_callback_remove(&list->move_cb, id);
156
}
157
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
158
void
1 by Daniel Holbach
Import upstream version 2.2.9
159
object_list_remove_geometry_cb(ObjectList_t *list, gpointer id)
160
{
161
   object_list_callback_remove(&list->geometry_cb, id);
162
}
163
164
Object_t*
165
object_init(Object_t *obj, ObjectClass_t *class)
166
{
167
   obj->class = class;
168
   obj->refcount = 1;
169
   obj->selected = FALSE;
170
   obj->locked = FALSE;
171
   obj->url = g_strdup("");
172
   obj->target = g_strdup("");
173
   obj->comment = g_strdup("");
174
   obj->mouse_over = g_strdup("");
175
   obj->mouse_out = g_strdup("");
176
   obj->focus = g_strdup("");
177
   obj->blur = g_strdup("");
178
   return obj;
179
}
180
181
static void
182
object_destruct(Object_t *obj)
183
{
184
   if (obj->class->destruct)
185
      obj->class->destruct(obj);
186
   g_free(obj->url);
187
   g_free(obj->target);
188
   g_free(obj->comment);
189
   g_free(obj->mouse_over);
190
   g_free(obj->mouse_out);
191
   g_free(obj->focus);
192
   g_free(obj->blur);
193
   g_free(obj);
194
}
195
196
Object_t*
197
object_ref(Object_t *obj)
198
{
199
   obj->refcount++;
200
   return obj;
201
}
202
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
203
void
1 by Daniel Holbach
Import upstream version 2.2.9
204
object_unref(Object_t *obj)
205
{
206
   if (!--obj->refcount)
207
      object_destruct(obj);
208
}
209
210
Object_t*
211
object_clone(Object_t *obj)
212
{
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
213
   Object_t *clone = obj->class->clone(obj);
1 by Daniel Holbach
Import upstream version 2.2.9
214
   clone->class = obj->class;
215
   clone->refcount = 1;
216
   clone->selected = obj->selected;
217
   clone->locked = FALSE;
218
   clone->url = g_strdup(obj->url);
219
   clone->target = g_strdup(obj->target);
220
   clone->comment = g_strdup(obj->comment);
221
   clone->mouse_over = g_strdup(obj->mouse_over);
222
   clone->mouse_out = g_strdup(obj->mouse_out);
223
   clone->focus = g_strdup(obj->focus);
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
224
   clone->blur = g_strdup(obj->blur);
1 by Daniel Holbach
Import upstream version 2.2.9
225
   return clone;
226
}
227
228
static Object_t*
229
object_copy(Object_t *src, Object_t *des)
230
{
231
   des->class = src->class;
232
   des->selected = src->selected;
233
   des->locked = FALSE;
234
   g_strreplace(&des->url, src->url);
235
   g_strreplace(&des->target, src->target);
236
   g_strreplace(&des->comment, src->comment);
237
   g_strreplace(&des->mouse_over, src->mouse_over);
238
   g_strreplace(&des->mouse_out, src->mouse_out);
239
   g_strreplace(&des->focus, src->focus);
240
   g_strreplace(&des->blur, src->blur);
241
   return des;
242
}
243
244
Object_t*
245
object_assign(Object_t *obj, Object_t *des)
246
{
247
   obj->class->assign(obj, des);
248
   return object_copy(obj, des);
249
}
250
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
251
void
1 by Daniel Holbach
Import upstream version 2.2.9
252
object_draw(Object_t *obj, GdkWindow *window)
253
{
254
   PreferencesData_t *preferences = get_preferences();
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
255
   GdkGC *gc = (obj->selected) ? preferences->selected_gc
1 by Daniel Holbach
Import upstream version 2.2.9
256
      : preferences->normal_gc;
257
   obj->class->draw(obj, window, gc);
258
   if (obj->selected && preferences->show_area_handle)
259
      obj->class->draw_sashes(obj, window, gc);
260
}
261
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
262
void
1 by Daniel Holbach
Import upstream version 2.2.9
263
object_edit(Object_t *obj, gboolean add)
264
{
265
   if (!obj->class->info_dialog)
266
      obj->class->info_dialog = create_edit_area_info_dialog(obj);
267
   edit_area_info_dialog_show(obj->class->info_dialog, obj, add);
268
}
269
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
270
void
1 by Daniel Holbach
Import upstream version 2.2.9
271
object_select(Object_t *obj)
272
{
273
   obj->selected = TRUE;
274
   object_list_callback_call(&obj->list->select_cb, obj);
275
   object_emit_geometry_signal(obj);
276
}
277
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
278
void
1 by Daniel Holbach
Import upstream version 2.2.9
279
object_unselect(Object_t *obj)
280
{
281
   obj->selected = FALSE;
282
   object_list_callback_call(&obj->list->select_cb, obj);
283
   object_emit_geometry_signal(obj);
284
}
285
286
void
287
object_move(Object_t *obj, gint dx, gint dy)
288
{
289
   obj->class->move(obj, dx, dy);
290
   object_emit_geometry_signal(obj);
291
}
292
293
void
1.1.5 by Daniel Holbach
Import upstream version 2.3.18
294
object_move_sash(Object_t *obj, gint dx, gint dy)
295
{
296
   gint x, y, width, height;
297
   MoveSashFunc_t sash_func;
298
299
   obj->class->get_dimensions(obj, &x, &y, &width, &height);
300
   if (dx == 0)
301
      x += (width / 2);
302
   else
303
      x += width;
304
305
   if (dy == 0)
306
      y += (height / 2);
307
   else
308
      y += height;
309
310
   sash_func = obj->class->near_sash(obj, x, y);
311
312
   if (sash_func) {
313
      sash_func(obj, dx, dy);
314
      object_emit_geometry_signal(obj);
315
   }
316
}
317
318
void
1 by Daniel Holbach
Import upstream version 2.2.9
319
object_remove(Object_t *obj)
320
{
321
   object_list_remove(obj->list, obj);
322
   object_emit_geometry_signal(obj);
323
}
324
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
325
void
1 by Daniel Holbach
Import upstream version 2.2.9
326
object_lock(Object_t *obj)
327
{
328
   obj->locked = TRUE;
329
}
330
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
331
void
1 by Daniel Holbach
Import upstream version 2.2.9
332
object_unlock(Object_t *obj)
333
{
334
   obj->locked = FALSE;
335
}
336
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
337
void
1 by Daniel Holbach
Import upstream version 2.2.9
338
object_set_url(Object_t *obj, const gchar *url)
339
{
340
   g_strreplace(&obj->url, url);
341
}
342
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
343
void
1 by Daniel Holbach
Import upstream version 2.2.9
344
object_set_target(Object_t *obj, const gchar *target)
345
{
346
   g_strreplace(&obj->target, target);
347
}
348
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
349
void
1 by Daniel Holbach
Import upstream version 2.2.9
350
object_set_comment(Object_t *obj, const gchar *comment)
351
{
352
   g_strreplace(&obj->comment, comment);
353
}
354
355
void
356
object_set_mouse_over(Object_t *obj, const gchar *mouse_over)
357
{
358
   g_strreplace(&obj->mouse_over, mouse_over);
359
}
360
361
void
362
object_set_mouse_out(Object_t *obj, const gchar *mouse_out)
363
{
364
   g_strreplace(&obj->mouse_out, mouse_out);
365
}
366
367
void
368
object_set_focus(Object_t *obj, const gchar *focus)
369
{
370
   g_strreplace(&obj->focus, focus);
371
}
372
373
void
374
object_set_blur(Object_t *obj, const gchar *blur)
375
{
376
   g_strreplace(&obj->blur, blur);
377
}
378
379
gint
380
object_get_position_in_list(Object_t *obj)
381
{
382
   return g_list_index(obj->list->list, (gpointer) obj);
383
}
384
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
385
void
1 by Daniel Holbach
Import upstream version 2.2.9
386
object_emit_changed_signal(Object_t *obj)
387
{
388
   object_list_callback_call(&obj->list->changed_cb, obj);
389
}
390
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
391
void
1 by Daniel Holbach
Import upstream version 2.2.9
392
object_emit_geometry_signal(Object_t *obj)
393
{
394
   object_list_callback_call(&obj->list->geometry_cb, obj);
395
}
396
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
397
void
1 by Daniel Holbach
Import upstream version 2.2.9
398
object_emit_update_signal(Object_t *obj)
399
{
400
   object_list_callback_call(&obj->list->update_cb, obj);
401
}
402
403
void
404
do_object_locked_dialog(void)
405
{
406
   static DefaultDialog_t *dialog;
407
   if (!dialog) {
408
      dialog = make_default_dialog("Object locked");
409
      default_dialog_hide_cancel_button(dialog);
410
      default_dialog_hide_apply_button(dialog);
411
      default_dialog_set_label(
412
	 dialog,
413
	 "\n  You cannot delete the selected object  \n"
414
	 "since it is currently being edited.\n");
415
   }
416
   default_dialog_show(dialog);
417
}
418
1.1.15 by Sebastien Bacher
Import upstream version 2.6.0
419
static Object_t*
1 by Daniel Holbach
Import upstream version 2.2.9
420
object_factory_create_object(ObjectFactory_t *factory, gint x, gint y)
421
{
422
   return factory->obj = factory->create_object(x, y);
423
}
424
425
static gboolean
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
426
button_motion(GtkWidget *widget, GdkEventMotion *event,
1 by Daniel Holbach
Import upstream version 2.2.9
427
	      ObjectFactory_t *factory)
428
{
429
   gint x = get_real_coord((gint) event->x);
430
   gint y = get_real_coord((gint) event->y);
431
432
   round_to_grid(&x, &y);
433
434
   object_draw(factory->obj, widget->window);
435
   factory->set_xy(factory->obj, event->state, x, y);
436
   object_draw(factory->obj, widget->window);
437
438
   return FALSE;
439
}
440
441
gboolean
442
object_on_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
443
{
444
   static ObjectFactory_t *factory;
445
   PreferencesData_t *preferences = get_preferences();
446
   gint x = get_real_coord((gint) event->x);
447
   gint y = get_real_coord((gint) event->y);
448
   static Object_t *obj;
449
450
   if (event->type == GDK_2BUTTON_PRESS)
451
      return FALSE;
452
   round_to_grid(&x, &y);
453
454
   if (obj) {
455
      if (event->button == 1) {
456
	 if (!factory->finish || factory->finish(obj, x, y)) {
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
457
	    g_signal_handlers_disconnect_by_func(widget,
458
                                                 button_motion,
1 by Daniel Holbach
Import upstream version 2.2.9
459
                                                 factory);
460
	    if (object_is_valid(obj)) {
461
	       Command_t *command = create_command_new(get_shapes(), obj);
462
	       command_execute(command);
463
	       if (preferences->prompt_for_area_info)
464
		  object_edit(obj, FALSE);
465
	    } else {
466
	       object_draw(obj, widget->window);
467
	       object_unref(obj);
468
	    }
469
	    gdk_gc_set_function(preferences->normal_gc, GDK_COPY);
470
	    obj = NULL;
471
	    main_clear_dimension();
472
	 }
473
      } else if (event->button == 3) {
474
	 object_draw(obj, widget->window);
475
	 if (!factory->cancel || factory->cancel(event, obj)) {
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
476
	    g_signal_handlers_disconnect_by_func(widget,
477
                                                 button_motion,
1 by Daniel Holbach
Import upstream version 2.2.9
478
                                                 factory);
479
	    object_unref(obj);
480
	    gdk_gc_set_function(preferences->normal_gc, GDK_COPY);
481
	    obj = NULL;
482
	    main_clear_dimension();
483
	 } else {
484
	    object_draw(obj, widget->window);
485
	 }
486
      }
487
   } else {
488
      if (event->button == 1) {
489
	 factory = ((ObjectFactory_t*(*)(guint)) data)(event->state);
490
	 obj = object_factory_create_object(factory, x, y);
1.1.5 by Daniel Holbach
Import upstream version 2.3.18
491
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
492
	 gdk_gc_set_function(preferences->normal_gc, GDK_XOR);
1 by Daniel Holbach
Import upstream version 2.2.9
493
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
494
	 g_signal_connect(widget, "motion-notify-event",
1 by Daniel Holbach
Import upstream version 2.2.9
495
                          G_CALLBACK(button_motion), factory);
496
      }
497
   }
498
   return FALSE;
499
}
500
501
ObjectList_t*
502
make_object_list(void)
503
{
504
  return g_new0 (ObjectList_t, 1);
505
}
506
507
void
508
object_list_destruct(ObjectList_t *list)
509
{
510
   object_list_remove_all(list);
511
   g_free(list->list);
512
}
513
514
ObjectList_t*
515
object_list_append_list(ObjectList_t *des, ObjectList_t *src)
516
{
517
   GList *p;
518
   for (p = src->list; p; p = p->next)
519
      object_list_append(des, object_clone((Object_t*) p->data));
520
   object_list_set_changed(des, (src) ? TRUE : FALSE);
521
   return des;
522
}
523
524
ObjectList_t*
525
object_list_copy(ObjectList_t *des, ObjectList_t *src)
526
{
527
   if (des)
528
      object_list_remove_all(des);
529
   else
530
      des = make_object_list();
531
532
   return object_list_append_list(des, src);
533
}
534
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
535
void
1 by Daniel Holbach
Import upstream version 2.2.9
536
object_list_append(ObjectList_t *list, Object_t *object)
537
{
538
   object->list = list;
539
   list->list = g_list_append(list->list, (gpointer) object);
540
   object_list_set_changed(list, TRUE);
541
   object_list_callback_call(&list->add_cb, object);
542
}
543
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
544
void
1 by Daniel Holbach
Import upstream version 2.2.9
545
object_list_prepend(ObjectList_t *list, Object_t *object)
546
{
547
   object->list = list;
548
   list->list = g_list_prepend(list->list, (gpointer) object);
549
   object_list_set_changed(list, TRUE);
550
   object_list_callback_call(&list->add_cb, object);
551
}
552
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
553
void
1 by Daniel Holbach
Import upstream version 2.2.9
554
object_list_insert(ObjectList_t *list, gint position, Object_t *object)
555
{
556
   object->list = list;
557
   list->list = g_list_insert(list->list, (gpointer) object, position);
558
   object_list_set_changed(list, TRUE);
559
   object_list_callback_call(&list->add_cb, object);
560
}
561
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
562
void
1 by Daniel Holbach
Import upstream version 2.2.9
563
object_list_remove(ObjectList_t *list, Object_t *object)
564
{
565
   list->list = g_list_remove(list->list, (gpointer) object);
566
   object_list_set_changed(list, TRUE);
567
   object_list_callback_call(&list->remove_cb, object);
568
   object_unref(object);
569
}
570
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
571
void
1 by Daniel Holbach
Import upstream version 2.2.9
572
object_list_remove_link(ObjectList_t *list, GList *link)
573
{
574
   list->list = g_list_remove_link(list->list, link);
575
   object_list_set_changed(list, TRUE);
576
   object_list_callback_call(&list->remove_cb, (Object_t*) link->data);
577
}
578
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
579
void
1 by Daniel Holbach
Import upstream version 2.2.9
580
object_list_update(ObjectList_t *list, Object_t *object)
581
{
582
   object_list_callback_call(&list->update_cb, object);
583
}
584
585
void
586
object_list_draw(ObjectList_t *list, GdkWindow *window)
587
{
588
   GList *p;
589
   for (p = list->list; p; p = p->next)
590
      object_draw((Object_t*) p->data, window);
591
}
592
593
void
594
object_list_draw_selected(ObjectList_t *list, GdkWindow *window)
595
{
596
   GList *p;
597
   for (p = list->list; p; p = p->next) {
598
      Object_t *obj = (Object_t*) p->data;
599
      if (obj->selected)
600
	 object_draw(obj, window);
601
   }
602
}
603
604
Object_t*
605
object_list_find(ObjectList_t *list, gint x, gint y)
606
{
607
   Object_t *found = NULL;
608
   GList *p;
609
   for (p = list->list; p; p = p->next) {
610
      Object_t *obj = (Object_t*) p->data;
611
      if (obj->class->point_is_on(obj, x, y))
612
	 found = obj;
613
   }
614
   return found;
615
}
616
617
Object_t*
618
object_list_near_sash(ObjectList_t *list, gint x, gint y,
619
		      MoveSashFunc_t *sash_func)
620
{
621
   Object_t *found = NULL;
622
   GList *p;
623
   for (p = list->list; p; p = p->next) {
624
      Object_t *obj = (Object_t*) p->data;
625
      if (obj->selected) {
626
	 MoveSashFunc_t func = obj->class->near_sash(obj, x, y);
627
	 if (func) {
628
	    found = obj;
629
	    *sash_func = func;
630
	 }
631
      }
632
   }
633
   return found;
634
}
635
636
void
637
object_list_remove_all(ObjectList_t *list)
638
{
639
   GList *p;
640
   for (p = list->list; p; p = p->next) {
641
      Object_t *obj = (Object_t*) p->data;
642
      object_list_callback_call(&list->remove_cb, obj);
643
      object_unref(obj);
644
   }
645
   g_list_free(list->list);
646
   list->list = NULL;
647
   object_list_set_changed(list, TRUE);
648
}
649
650
void
651
clear_paste_buffer(void)
652
{
653
   if (_paste_buffer)
654
      object_list_remove_all(_paste_buffer);
655
   else
656
      _paste_buffer = make_object_list();
657
}
658
659
ObjectList_t*
660
get_paste_buffer(void)
661
{
662
   return _paste_buffer;
663
}
664
665
gint
666
object_list_cut(ObjectList_t *list)
667
{
668
   GList *p, *q;
669
   gint count = 0;
670
671
   clear_paste_buffer();
672
   for (p = list->list; p; p = q) {
673
      Object_t *obj = (Object_t*) p->data;
674
      q = p->next;
675
      if (obj->selected) {
676
	 if (obj->locked) {
677
	    do_object_locked_dialog();
678
	 } else {
679
	    object_list_append(_paste_buffer, obj);
680
	    object_list_remove_link(list, p);
681
	    count++;
682
	 }
683
      }
684
   }
685
   object_list_set_changed(list, (count) ? TRUE : FALSE);
686
   return count;
687
}
688
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
689
void
1 by Daniel Holbach
Import upstream version 2.2.9
690
object_list_copy_to_paste_buffer(ObjectList_t *list)
691
{
692
   GList *p;
693
694
   clear_paste_buffer();
695
   for (p = list->list; p; p = p->next) {
696
      Object_t *obj = (Object_t*) p->data;
697
      if (obj->selected)
698
	 object_list_append(_paste_buffer, object_clone(obj));
699
   }
700
}
701
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
702
void
1 by Daniel Holbach
Import upstream version 2.2.9
703
object_list_paste(ObjectList_t *list)
704
{
705
   object_list_append_list(list, _paste_buffer);
706
}
707
708
void
709
object_list_delete_selected(ObjectList_t *list)
710
{
711
   GList *p, *q;
712
   for (p = list->list; p; p = q) {
713
      Object_t *obj = (Object_t*) p->data;
714
      q = p->next;
715
      if (obj->selected) {
716
	 if (obj->locked) {
717
	    do_object_locked_dialog();
718
	 } else {
719
	    object_list_remove_link(list, p);
720
	    object_unref(obj);
721
	 }
722
      }
723
   }
724
}
725
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
726
void
1 by Daniel Holbach
Import upstream version 2.2.9
727
object_list_edit_selected(ObjectList_t *list)
728
{
729
   GList *p;
730
   for (p = list->list; p; p = p->next) {
731
      Object_t *obj = (Object_t*) p->data;
732
      if (obj->selected) {
733
	 object_edit(obj, TRUE);
734
	 break;
735
      }
736
   }
737
}
738
739
gint
740
object_list_select_all(ObjectList_t *list)
741
{
742
   GList *p;
743
   gint count = 0;
744
   for (p = list->list; p; p = p->next) {
745
      Object_t *obj = (Object_t*) p->data;
746
      if (!obj->selected) {
747
	 object_select(obj);
748
	 count++;
749
      }
750
   }
751
   return count;
752
}
753
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
754
void
1 by Daniel Holbach
Import upstream version 2.2.9
755
object_list_select_next(ObjectList_t *list)
756
{
757
   GList *p;
758
   for (p = list->list; p; p = p->next) {
759
      Object_t *obj = (Object_t*) p->data;
760
      if (obj->selected) {
761
	 object_unselect(obj);
762
	 p = (p->next) ? p->next : list->list;
763
	 object_select((Object_t*) p->data);
764
	 for (p = p->next; p; p = p->next) {
765
	    obj = (Object_t*) p->data;
766
	    if (obj->selected)
767
	       object_unselect(obj);
768
	 }
769
	 break;
770
      }
771
   }
772
}
773
774
void object_list_select_prev(ObjectList_t *list)
775
{
776
   GList *p;
777
   for (p = list->list; p; p = p->next) {
778
      Object_t *obj = (Object_t*) p->data;
779
      if (obj->selected) {
780
	 GList *q = (p->prev) ? p->prev : g_list_last(list->list);
781
	 for (; p; p = p->next) {
782
	    obj = (Object_t*) p->data;
783
	    if (obj->selected)
784
	       object_unselect(obj);
785
	 }
786
	 object_select((Object_t*) q->data);
787
	 break;
788
      }
789
   }
790
}
791
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
792
gint
1 by Daniel Holbach
Import upstream version 2.2.9
793
object_list_select_region(ObjectList_t *list, gint x, gint y, gint width,
794
			  gint height)
795
{
796
   GList *p;
797
   gint count = 0;
798
   for (p = list->list; p; p = p->next) {
799
      Object_t *obj = (Object_t*) p->data;
800
      gint obj_x, obj_y, obj_width, obj_height;
801
802
      object_get_dimensions(obj, &obj_x, &obj_y, &obj_width, &obj_height);
803
      if (obj_x >= x && obj_x + obj_width <= x + width &&
804
	  obj_y >= y && obj_y + obj_height <= y + height) {
805
	 object_select(obj);
806
	 count++;
807
      }
808
   }
809
   return count;
810
}
811
812
gint
813
object_list_deselect_all(ObjectList_t *list, Object_t *exception)
814
{
815
   GList *p;
816
   gint count = 0;
817
   for (p = list->list; p; p = p->next) {
818
      Object_t *obj = (Object_t*) p->data;
819
      if (obj->selected && obj != exception) {
820
	 object_unselect(obj);
821
	 count++;
822
      }
823
   }
824
   return count;
825
}
826
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
827
gint
1 by Daniel Holbach
Import upstream version 2.2.9
828
object_list_nr_selected(ObjectList_t *list)
829
{
830
   GList *p;
831
   gint count = 0;
832
   for (p = list->list; p; p = p->next) {
833
      Object_t *obj = (Object_t*) p->data;
834
      if (obj->selected)
835
	 count++;
836
   }
837
   return count;
838
}
839
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
840
void
1 by Daniel Holbach
Import upstream version 2.2.9
841
object_list_resize(ObjectList_t *list, gint percentage_x, gint percentage_y)
842
{
843
   GList *p;
844
   for (p = list->list; p; p = p->next) {
845
      Object_t *obj = (Object_t*) p->data;
846
      object_resize(obj, percentage_x, percentage_y);
847
   }
848
}
849
850
static void
851
object_list_swap_prev(ObjectList_t *list, GList *p)
852
{
853
   gpointer swap = p->data;
854
   p->data = p->prev->data;
855
   p->prev->data = swap;
856
   object_list_callback_call(&list->move_cb, (Object_t*) p->data);
857
   object_list_callback_call(&list->move_cb, (Object_t*) p->prev->data);
858
}
859
860
static void
861
object_list_swap_next(ObjectList_t *list, GList *p)
862
{
863
   gpointer swap = p->data;
864
   p->data = p->next->data;
865
   p->next->data = swap;
866
   object_list_callback_call(&list->move_cb, (Object_t*) p->data);
867
   object_list_callback_call(&list->move_cb, (Object_t*) p->next->data);
868
}
869
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
870
void
1 by Daniel Holbach
Import upstream version 2.2.9
871
object_list_move_selected(ObjectList_t *list, gint dx, gint dy)
872
{
873
   GList *p;
874
   for (p = list->list; p; p = p->next) {
875
      Object_t *obj = (Object_t*) p->data;
876
      if (obj->selected)
877
	 object_move(obj, dx, dy);
878
   }
879
}
880
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
881
void
1 by Daniel Holbach
Import upstream version 2.2.9
882
object_list_move_up(ObjectList_t *list, Object_t *obj)
883
{
884
   GList *p = g_list_find(list->list, (gpointer) obj);
885
   object_list_swap_prev(list, p);
886
}
887
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
888
void
1 by Daniel Holbach
Import upstream version 2.2.9
889
object_list_move_down(ObjectList_t *list, Object_t *obj)
890
{
891
   GList *p = g_list_find(list->list, (gpointer) obj);
892
   object_list_swap_next(list, p);
893
}
894
895
void
896
object_list_move_selected_up(ObjectList_t *list)
897
{
898
   GList *p;
899
900
   for (p = list->list; p; p = p->next) {
901
      Object_t *obj = (Object_t*) p->data;
902
      if (obj->selected && p->prev)
903
	 object_list_swap_prev(list, p);
904
   }
905
}
906
907
void
908
object_list_move_selected_down(ObjectList_t *list)
909
{
910
   GList *p;
911
912
   for (p = g_list_last(list->list); p; p = p->prev) {
913
      Object_t *obj = (Object_t*) p->data;
914
      if (obj->selected && p->next)
915
	 object_list_swap_next(list, p);
916
   }
917
}
918
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
919
void
1 by Daniel Holbach
Import upstream version 2.2.9
920
object_list_move_to_front(ObjectList_t *list)
921
{
922
   GList *p, *q;
923
   guint length = g_list_length(list->list);
924
925
   for (p = list->list; length; p = q, length--) {
926
      Object_t *obj = (Object_t*) p->data;
927
      q = p->next;
928
      if (obj->selected) {
929
	 object_list_remove_link(list, p);
930
	 object_list_append(list, obj);
931
      }
932
   }
933
}
934
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
935
void
1 by Daniel Holbach
Import upstream version 2.2.9
936
object_list_send_to_back(ObjectList_t *list)
937
{
938
   GList *p, *q;
939
   guint length = g_list_length(list->list);
940
941
   for (p = list->list; length; p = q, length--) {
942
      Object_t *obj = (Object_t*) p->data;
943
      q = p->next;
944
      if (obj->selected) {
945
	 object_list_remove_link(list, p);
946
	 object_list_prepend(list, obj);
947
      }
948
   }
949
}
950
1.1.5 by Daniel Holbach
Import upstream version 2.3.18
951
void
952
object_list_move_sash_selected(ObjectList_t *list, gint dx, gint dy)
953
{
954
   GList *p;
955
   for (p = list->list; p; p = p->next) {
956
      Object_t *obj = (Object_t*) p->data;
957
      if (obj->selected)
958
	 object_move_sash(obj, dx, dy);
959
   }
960
}
961
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
962
static void
1 by Daniel Holbach
Import upstream version 2.2.9
963
write_xml_attrib(const gchar *attrib, const gchar *value,
1.1.4 by Daniel Holbach
Import upstream version 2.3.16
964
		 const gchar *default_text, gpointer param,
1 by Daniel Holbach
Import upstream version 2.2.9
965
		 OutputFunc_t output)
966
{
967
   if (*value) {
968
      gchar *escaped_value = g_markup_escape_text(value, -1);
969
      output(param, " %s=\"%s\"", attrib, escaped_value);
970
      g_free(escaped_value);
971
   } else if (*default_text) {
972
      output(param, " %s", default_text);
973
   }
974
}
975
976
void
977
object_list_write_csim(ObjectList_t *list, gpointer param, OutputFunc_t output)
978
{
979
   GList *p;
980
   for (p = list->list; p; p = p->next) {
981
      Object_t *obj = (Object_t*) p->data;
982
983
      output(param, "<area shape=");
984
      obj->class->write_csim(obj, param, output);
985
986
      write_xml_attrib("alt", obj->comment, "", param, output);
987
      write_xml_attrib("target", obj->target, "", param, output);
988
      write_xml_attrib("onmouseover", obj->mouse_over, "", param, output);
989
      write_xml_attrib("onmouseout", obj->mouse_out, "", param, output);
990
      write_xml_attrib("onfocus", obj->focus, "", param, output);
991
      write_xml_attrib("onblur", obj->blur, "", param, output);
992
      write_xml_attrib("href", obj->url, " nohref=\"nohref\"", param, output);
993
      output(param," />\n");
994
   }
995
}
996
997
void
998
object_list_write_cern(ObjectList_t *list, gpointer param, OutputFunc_t output)
999
{
1000
   GList *p;
1001
   for (p = list->list; p; p = p->next) {
1002
      Object_t *obj = (Object_t*) p->data;
1003
      obj->class->write_cern(obj, param, output);
1004
      output(param, " %s\n", obj->url);
1005
   }
1006
}
1007
1008
void
1009
object_list_write_ncsa(ObjectList_t *list, gpointer param, OutputFunc_t output)
1010
{
1011
   GList *p;
1012
   for (p = list->list; p; p = p->next) {
1013
      Object_t *obj = (Object_t*) p->data;
1014
1015
      if (*obj->comment)
1016
	 output(param, "# %s\n", obj->comment);
1017
      obj->class->write_ncsa(obj, param, output);
1018
      output(param, "\n");
1019
   }
1020
}