~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to plug-ins/imagemap/imap_object.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * Copyright (C) 1998-2005 Maurits Rijk  m.rijk@chello.nl
7
7
 *
8
 
 * This program is free software; you can redistribute it and/or modify
 
8
 * This program is free software: you can redistribute it and/or modify
9
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
 
10
 * the Free Software Foundation; either version 3 of the License, or
11
11
 * (at your option) any later version.
12
12
 *
13
13
 * This program is distributed in the hope that it will be useful,
16
16
 * GNU General Public License for more details.
17
17
 *
18
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.
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
20
 *
22
21
 */
23
22
 
41
40
 
42
41
static gpointer
43
42
object_list_callback_add(ObjectListCallback_t *list,
44
 
                         ObjectListCallbackFunc_t func, gpointer data)
 
43
                         ObjectListCallbackFunc_t func, gpointer data)
45
44
{
46
45
   ObjectListCB_t *cb = g_new(ObjectListCB_t, 1);
47
46
   cb->func = func;
68
67
 
69
68
gpointer
70
69
object_list_add_changed_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
71
 
                           gpointer data)
 
70
                           gpointer data)
72
71
{
73
72
   return object_list_callback_add(&list->changed_cb, func, data);
74
73
}
75
74
 
76
75
gpointer
77
76
object_list_add_update_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
78
 
                          gpointer data)
 
77
                          gpointer data)
79
78
{
80
79
   return object_list_callback_add(&list->update_cb, func, data);
81
80
}
82
81
 
83
82
gpointer
84
83
object_list_add_add_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
85
 
                       gpointer data)
 
84
                       gpointer data)
86
85
{
87
86
   return object_list_callback_add(&list->add_cb, func, data);
88
87
}
89
88
 
90
89
gpointer
91
90
object_list_add_remove_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
92
 
                          gpointer data)
 
91
                          gpointer data)
93
92
{
94
93
   return object_list_callback_add(&list->remove_cb, func, data);
95
94
}
96
95
 
97
96
gpointer
98
97
object_list_add_select_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
99
 
                          gpointer data)
 
98
                          gpointer data)
100
99
{
101
100
   return object_list_callback_add(&list->select_cb, func, data);
102
101
}
103
102
 
104
103
gpointer
105
104
object_list_add_move_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
106
 
                        gpointer data)
 
105
                        gpointer data)
107
106
{
108
107
   return object_list_callback_add(&list->move_cb, func, data);
109
108
}
110
109
 
111
110
gpointer
112
111
object_list_add_geometry_cb(ObjectList_t *list, ObjectListCallbackFunc_t func,
113
 
                            gpointer data)
 
112
                            gpointer data)
114
113
{
115
114
   return object_list_callback_add(&list->geometry_cb, func, data);
116
115
}
249
248
}
250
249
 
251
250
void
252
 
object_draw(Object_t *obj, GdkWindow *window)
 
251
object_draw(Object_t *obj, cairo_t *cr)
253
252
{
254
253
   PreferencesData_t *preferences = get_preferences();
255
 
   GdkGC *gc = (obj->selected) ? preferences->selected_gc
256
 
      : preferences->normal_gc;
257
 
   obj->class->draw(obj, window, gc);
 
254
   ColorSelData_t *colors = &preferences->colors;
 
255
   GdkColor *fg, *bg;
 
256
   gdouble dash = 4.;
 
257
 
 
258
   if (obj->selected & 4) {
 
259
      fg = &colors->interactive_fg;
 
260
      bg = &colors->interactive_bg;
 
261
      obj->selected &= ~4;
 
262
   } else if (obj->selected) {
 
263
      fg = &colors->selected_fg;
 
264
      bg = &colors->selected_bg;
 
265
   } else {
 
266
      fg = &colors->normal_fg;
 
267
      bg = &colors->normal_bg;
 
268
   }
 
269
   
 
270
   cairo_save (cr);
 
271
   gdk_cairo_set_source_color (cr, bg);
 
272
   obj->class->draw(obj, cr);
 
273
   gdk_cairo_set_source_color (cr, fg);
 
274
   cairo_set_dash (cr, &dash, 1, 0.);
 
275
   obj->class->draw(obj, cr);
 
276
 
258
277
   if (obj->selected && preferences->show_area_handle)
259
 
      obj->class->draw_sashes(obj, window, gc);
 
278
      obj->class->draw_sashes(obj, cr);
 
279
   cairo_restore (cr);
260
280
}
261
281
 
262
282
void
409
429
      default_dialog_hide_cancel_button(dialog);
410
430
      default_dialog_hide_apply_button(dialog);
411
431
      default_dialog_set_label(
412
 
         dialog,
413
 
         "\n  You cannot delete the selected object  \n"
414
 
         "since it is currently being edited.\n");
 
432
         dialog,
 
433
         "\n  You cannot delete the selected object  \n"
 
434
         "since it is currently being edited.\n");
415
435
   }
416
436
   default_dialog_show(dialog);
417
437
}
424
444
 
425
445
static gboolean
426
446
button_motion(GtkWidget *widget, GdkEventMotion *event,
427
 
              ObjectFactory_t *factory)
 
447
              ObjectFactory_t *factory)
428
448
{
429
449
   gint x = get_real_coord((gint) event->x);
430
450
   gint y = get_real_coord((gint) event->y);
431
451
 
432
452
   round_to_grid(&x, &y);
433
453
 
434
 
   object_draw(factory->obj, widget->window);
435
454
   factory->set_xy(factory->obj, event->state, x, y);
436
 
   object_draw(factory->obj, widget->window);
 
455
 
 
456
   preview_redraw ();
437
457
 
438
458
   return FALSE;
439
459
}
453
473
 
454
474
   if (obj) {
455
475
      if (event->button == 1) {
456
 
         if (!factory->finish || factory->finish(obj, x, y)) {
457
 
            g_signal_handlers_disconnect_by_func(widget,
 
476
         if (!factory->finish || factory->finish(obj, x, y)) {
 
477
            g_signal_handlers_disconnect_by_func(widget,
458
478
                                                 button_motion,
459
479
                                                 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
 
         }
 
480
            if (object_is_valid(obj)) {
 
481
               Command_t *command = create_command_new(get_shapes(), obj);
 
482
               command_execute(command);
 
483
               if (preferences->prompt_for_area_info)
 
484
                  object_edit(obj, FALSE);
 
485
            } else {
 
486
               object_unref(obj);
 
487
            }
 
488
            preview_unset_tmp_obj (obj);
 
489
            preview_redraw ();
 
490
            obj = NULL;
 
491
            main_clear_dimension();
 
492
         }
473
493
      } else if (event->button == 3) {
474
 
         object_draw(obj, widget->window);
475
 
         if (!factory->cancel || factory->cancel(event, obj)) {
476
 
            g_signal_handlers_disconnect_by_func(widget,
 
494
         if (!factory->cancel || factory->cancel(event, obj)) {
 
495
            g_signal_handlers_disconnect_by_func(widget,
477
496
                                                 button_motion,
478
497
                                                 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
 
         }
 
498
            object_unref(obj);
 
499
            preview_unset_tmp_obj (obj);
 
500
            preview_redraw ();
 
501
            obj = NULL;
 
502
            main_clear_dimension();
 
503
         }
 
504
         return TRUE;
486
505
      }
487
506
   } else {
488
507
      if (event->button == 1) {
489
 
         factory = ((ObjectFactory_t*(*)(guint)) data)(event->state);
490
 
         obj = object_factory_create_object(factory, x, y);
491
 
 
492
 
         gdk_gc_set_function(preferences->normal_gc, GDK_XOR);
493
 
 
494
 
         g_signal_connect(widget, "motion-notify-event",
 
508
         factory = ((ObjectFactory_t*(*)(guint)) data)(event->state);
 
509
         obj = object_factory_create_object(factory, x, y);
 
510
         preview_set_tmp_obj (obj);
 
511
 
 
512
         g_signal_connect(widget, "motion-notify-event",
495
513
                          G_CALLBACK(button_motion), factory);
496
514
      }
497
515
   }
583
601
}
584
602
 
585
603
void
586
 
object_list_draw(ObjectList_t *list, GdkWindow *window)
 
604
object_list_draw(ObjectList_t *list, cairo_t *cr)
587
605
{
588
606
   GList *p;
589
607
   for (p = list->list; p; p = p->next)
590
 
      object_draw((Object_t*) p->data, window);
 
608
      object_draw((Object_t*) p->data, cr);
591
609
}
592
610
 
593
611
void
594
 
object_list_draw_selected(ObjectList_t *list, GdkWindow *window)
 
612
object_list_draw_selected(ObjectList_t *list, cairo_t *cr)
595
613
{
596
614
   GList *p;
597
615
   for (p = list->list; p; p = p->next) {
598
616
      Object_t *obj = (Object_t*) p->data;
599
617
      if (obj->selected)
600
 
         object_draw(obj, window);
 
618
         object_draw(obj, cr);
601
619
   }
602
620
}
603
621
 
609
627
   for (p = list->list; p; p = p->next) {
610
628
      Object_t *obj = (Object_t*) p->data;
611
629
      if (obj->class->point_is_on(obj, x, y))
612
 
         found = obj;
 
630
         found = obj;
613
631
   }
614
632
   return found;
615
633
}
616
634
 
617
635
Object_t*
618
636
object_list_near_sash(ObjectList_t *list, gint x, gint y,
619
 
                      MoveSashFunc_t *sash_func)
 
637
                      MoveSashFunc_t *sash_func)
620
638
{
621
639
   Object_t *found = NULL;
622
640
   GList *p;
623
641
   for (p = list->list; p; p = p->next) {
624
642
      Object_t *obj = (Object_t*) p->data;
625
643
      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
 
         }
 
644
         MoveSashFunc_t func = obj->class->near_sash(obj, x, y);
 
645
         if (func) {
 
646
            found = obj;
 
647
            *sash_func = func;
 
648
         }
631
649
      }
632
650
   }
633
651
   return found;
673
691
      Object_t *obj = (Object_t*) p->data;
674
692
      q = p->next;
675
693
      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
 
         }
 
694
         if (obj->locked) {
 
695
            do_object_locked_dialog();
 
696
         } else {
 
697
            object_list_append(_paste_buffer, obj);
 
698
            object_list_remove_link(list, p);
 
699
            count++;
 
700
         }
683
701
      }
684
702
   }
685
703
   object_list_set_changed(list, (count) ? TRUE : FALSE);
695
713
   for (p = list->list; p; p = p->next) {
696
714
      Object_t *obj = (Object_t*) p->data;
697
715
      if (obj->selected)
698
 
         object_list_append(_paste_buffer, object_clone(obj));
 
716
         object_list_append(_paste_buffer, object_clone(obj));
699
717
   }
700
718
}
701
719
 
713
731
      Object_t *obj = (Object_t*) p->data;
714
732
      q = p->next;
715
733
      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
 
         }
 
734
         if (obj->locked) {
 
735
            do_object_locked_dialog();
 
736
         } else {
 
737
            object_list_remove_link(list, p);
 
738
            object_unref(obj);
 
739
         }
722
740
      }
723
741
   }
724
742
}
730
748
   for (p = list->list; p; p = p->next) {
731
749
      Object_t *obj = (Object_t*) p->data;
732
750
      if (obj->selected) {
733
 
         object_edit(obj, TRUE);
734
 
         break;
 
751
         object_edit(obj, TRUE);
 
752
         break;
735
753
      }
736
754
   }
737
755
}
744
762
   for (p = list->list; p; p = p->next) {
745
763
      Object_t *obj = (Object_t*) p->data;
746
764
      if (!obj->selected) {
747
 
         object_select(obj);
748
 
         count++;
 
765
         object_select(obj);
 
766
         count++;
749
767
      }
750
768
   }
751
769
   return count;
758
776
   for (p = list->list; p; p = p->next) {
759
777
      Object_t *obj = (Object_t*) p->data;
760
778
      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;
 
779
         object_unselect(obj);
 
780
         p = (p->next) ? p->next : list->list;
 
781
         object_select((Object_t*) p->data);
 
782
         for (p = p->next; p; p = p->next) {
 
783
            obj = (Object_t*) p->data;
 
784
            if (obj->selected)
 
785
               object_unselect(obj);
 
786
         }
 
787
         break;
770
788
      }
771
789
   }
772
790
}
777
795
   for (p = list->list; p; p = p->next) {
778
796
      Object_t *obj = (Object_t*) p->data;
779
797
      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;
 
798
         GList *q = (p->prev) ? p->prev : g_list_last(list->list);
 
799
         for (; p; p = p->next) {
 
800
            obj = (Object_t*) p->data;
 
801
            if (obj->selected)
 
802
               object_unselect(obj);
 
803
         }
 
804
         object_select((Object_t*) q->data);
 
805
         break;
788
806
      }
789
807
   }
790
808
}
791
809
 
792
810
gint
793
811
object_list_select_region(ObjectList_t *list, gint x, gint y, gint width,
794
 
                          gint height)
 
812
                          gint height)
795
813
{
796
814
   GList *p;
797
815
   gint count = 0;
801
819
 
802
820
      object_get_dimensions(obj, &obj_x, &obj_y, &obj_width, &obj_height);
803
821
      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++;
 
822
          obj_y >= y && obj_y + obj_height <= y + height) {
 
823
         object_select(obj);
 
824
         count++;
807
825
      }
808
826
   }
809
827
   return count;
817
835
   for (p = list->list; p; p = p->next) {
818
836
      Object_t *obj = (Object_t*) p->data;
819
837
      if (obj->selected && obj != exception) {
820
 
         object_unselect(obj);
821
 
         count++;
 
838
         object_unselect(obj);
 
839
         count++;
822
840
      }
823
841
   }
824
842
   return count;
832
850
   for (p = list->list; p; p = p->next) {
833
851
      Object_t *obj = (Object_t*) p->data;
834
852
      if (obj->selected)
835
 
         count++;
 
853
         count++;
836
854
   }
837
855
   return count;
838
856
}
874
892
   for (p = list->list; p; p = p->next) {
875
893
      Object_t *obj = (Object_t*) p->data;
876
894
      if (obj->selected)
877
 
         object_move(obj, dx, dy);
 
895
         object_move(obj, dx, dy);
878
896
   }
879
897
}
880
898
 
900
918
   for (p = list->list; p; p = p->next) {
901
919
      Object_t *obj = (Object_t*) p->data;
902
920
      if (obj->selected && p->prev)
903
 
         object_list_swap_prev(list, p);
 
921
         object_list_swap_prev(list, p);
904
922
   }
905
923
}
906
924
 
912
930
   for (p = g_list_last(list->list); p; p = p->prev) {
913
931
      Object_t *obj = (Object_t*) p->data;
914
932
      if (obj->selected && p->next)
915
 
         object_list_swap_next(list, p);
 
933
         object_list_swap_next(list, p);
916
934
   }
917
935
}
918
936
 
926
944
      Object_t *obj = (Object_t*) p->data;
927
945
      q = p->next;
928
946
      if (obj->selected) {
929
 
         object_list_remove_link(list, p);
930
 
         object_list_append(list, obj);
 
947
         object_list_remove_link(list, p);
 
948
         object_list_append(list, obj);
931
949
      }
932
950
   }
933
951
}
942
960
      Object_t *obj = (Object_t*) p->data;
943
961
      q = p->next;
944
962
      if (obj->selected) {
945
 
         object_list_remove_link(list, p);
946
 
         object_list_prepend(list, obj);
 
963
         object_list_remove_link(list, p);
 
964
         object_list_prepend(list, obj);
947
965
      }
948
966
   }
949
967
}
955
973
   for (p = list->list; p; p = p->next) {
956
974
      Object_t *obj = (Object_t*) p->data;
957
975
      if (obj->selected)
958
 
         object_move_sash(obj, dx, dy);
 
976
         object_move_sash(obj, dx, dy);
959
977
   }
960
978
}
961
979
 
962
980
static void
963
981
write_xml_attrib(const gchar *attrib, const gchar *value,
964
 
                 const gchar *default_text, gpointer param,
965
 
                 OutputFunc_t output)
 
982
                 const gchar *default_text, gpointer param,
 
983
                 OutputFunc_t output)
966
984
{
967
985
   if (*value) {
968
986
      gchar *escaped_value = g_markup_escape_text(value, -1);
1013
1031
      Object_t *obj = (Object_t*) p->data;
1014
1032
 
1015
1033
      if (*obj->comment)
1016
 
         output(param, "# %s\n", obj->comment);
 
1034
         output(param, "# %s\n", obj->comment);
1017
1035
      obj->class->write_ncsa(obj, param, output);
1018
1036
      output(param, "\n");
1019
1037
   }