summaryrefslogtreecommitdiffstats
path: root/graphics/gimp-devel/files/patch-ah
blob: 8e508d8ad219bd91d523859abedce30a2246eb93 (plain)
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
--- app/autodialog.c.old	Fri Nov 22 15:46:44 1996
+++ app/autodialog.c	Fri Nov 22 18:08:40 1996
@@ -49,7 +49,7 @@
 /*  Local functions  */
 static AutoDialogItem dialog_find_item (AutoDialog, int);
 static void dialog_delete_children (AutoDialog, AutoDialogItem);
-static GtkWidget *dialog_create_image_menu (AutoDialog, char *, gpointer,
+static GtkWidget *dialog_create_image_menu (AutoDialog, AutoDialogItem, char *, gpointer,
 					    GtkWidget **, GtkWidget **);
 
 /*  Callback and Update functions  */
@@ -171,7 +171,8 @@
 	{
 	  dlgitem = tmplink->data;
 	  tmplink = tmplink->next;
-
+    if (dlgitem->additional_data!=NULL)
+      xfree(dlgitem->additional_data);
 	  xfree (dlgitem);
 	}
       free_list (dlg->items);
@@ -206,6 +207,7 @@
   item->item_ID = dlg->next_item_ID++;
   item->item_type = type;
   memset (item->data, 0, 32);
+  item->additional_data=NULL;
   item->parent = parent_item;
   item->children = NULL;
   item->gtk_data = NULL;
@@ -276,7 +278,7 @@
       break;
 
     case ITEM_IMAGE_MENU:
-      item_widget = dialog_create_image_menu (dlg, data, extra, &option_menu, &menu);
+      item_widget = dialog_create_image_menu (dlg, item, data, extra, &option_menu, &menu);
       break;
 
     case ITEM_SCALE:
@@ -500,7 +502,8 @@
 	}
       else
 	gtk_widget_destroy (item->widget);
-
+      if (item->additional_data!=NULL)
+        xfree(item->additional_data);
       xfree (item);
     }
 }
@@ -577,9 +580,32 @@
     free_list (item->children);
 }
 
+typedef struct {
+  GtkWidget *widget;
+  long data[2];
+} _MenuItemData;
+
+gint CheckConstrains(GImage *gimage,GImage *constrain,guchar constraint)
+{
+  if (((constraint & IMAGE_CONSTRAIN_RGB) &&
+       (gimage_type (gimage) == RGB_GIMAGE ||
+	      gimage_type (gimage) == RGBA_GIMAGE)) ||
+	    ((constraint & IMAGE_CONSTRAIN_GRAY) &&
+	     (gimage_type (gimage) == GRAY_GIMAGE ||
+	      gimage_type (gimage) == GRAYA_GIMAGE)) ||
+	    ((constraint & IMAGE_CONSTRAIN_INDEXED) &&
+	     (gimage_type (gimage) == INDEXED_GIMAGE ||
+	      gimage_type (gimage) == INDEXEDA_GIMAGE)))
+    if ((gimage->width == constrain->width) &&
+	      (gimage->height == constrain->height))
+      return(TRUE);
+  return(FALSE); 
+}
+
 static GtkWidget *
-dialog_create_image_menu (dlg, title, image, option_menu, menu)
+dialog_create_image_menu (dlg, item, title, image, option_menu, menu)
      AutoDialog dlg;
+     AutoDialogItem item;
      char *title;
      void *image;
      GtkWidget **option_menu;
@@ -597,8 +623,8 @@
   char constraint;
   link_ptr tmp;
   long ID;
-  long *data;
   int num_items = 0;
+  _MenuItemData *ItemData;
 
   hbox = gtk_hbox_new (FALSE, 4);
   gtk_container_set_border_width (hbox, 0);
@@ -614,43 +640,55 @@
   constrain = (ID == 0) ? image : gimage_get_ID (ID);
 
   tmp = image_list;
+
+  /* Check how many images fit the criteria */
+  /* ====================================== */
+
   while (tmp)
     {
       gimage = tmp->data;
       tmp = next_item (tmp);
-
-      if (((constraint & IMAGE_CONSTRAIN_RGB) &&
-	   (gimage_type (gimage) == RGB_GIMAGE ||
-	    gimage_type (gimage) == RGBA_GIMAGE)) ||
-	  ((constraint & IMAGE_CONSTRAIN_GRAY) &&
-	   (gimage_type (gimage) == GRAY_GIMAGE ||
-	    gimage_type (gimage) == GRAYA_GIMAGE)) ||
-	  ((constraint & IMAGE_CONSTRAIN_INDEXED) &&
-	   (gimage_type (gimage) == INDEXED_GIMAGE ||
-	    gimage_type (gimage) == INDEXEDA_GIMAGE)))
-	if ((gimage->width == constrain->width) &&
-	    (gimage->height == constrain->height))
-	  {
-	    image_name = prune_filename (gimage_filename (gimage));
-	    menu_item_label = (char *) xmalloc (strlen (image_name) + 15);
-	    sprintf (menu_item_label, "%s-%d", image_name, gimage->ID);
-	    menu_item = gtk_menu_item_new_with_label (menu_item_label);
-	    gtk_callback_add (gtk_menu_item_get_state (menu_item),
-			      dialog_image_menu_callback, dlg);
-	    gtk_container_add (*menu, menu_item);
-	    gtk_widget_show (menu_item);
-
-	    data = xmalloc (sizeof (long) * 2);
-	    data[0] = dlg->next_item_ID - 1;
-	    data[1] = (gimage->ID == constrain->ID) ? 0 : gimage->ID;
-	    dlg->additional_data = data;
-
-	    xfree (menu_item_label);
-	    num_items ++;
-	  }
+      if (CheckConstrains(gimage,constrain,constraint)==TRUE)
+        num_items++;      
     }
 
-  if (!num_items)
+  /* If we found any matches, allocate memory to hold      */
+  /* callback data. Put a pointer in "item" to avoid leak. */
+  /* ===================================================== */
+  
+  if (num_items>0)
+    {
+      ItemData=(_MenuItemData *)xmalloc(sizeof(_MenuItemData)*(size_t)num_items);
+      item->additional_data=ItemData;
+
+      tmp=image_list;
+      num_items=0;
+      while (tmp)
+        {
+          gimage = tmp->data;
+          tmp = next_item (tmp);
+          if (CheckConstrains(gimage,constrain,constraint)==TRUE)
+	          {
+	            image_name = prune_filename (gimage_filename (gimage));
+	            menu_item_label = (char *) xmalloc (strlen (image_name) + 15);
+	            sprintf (menu_item_label, "%s-%d", image_name, gimage->ID);
+      
+              ItemData[num_items].widget=hbox;
+              ItemData[num_items].data[0] = dlg->next_item_ID - 1;
+              ItemData[num_items].data[1] = (gimage->ID == constrain->ID) ? 0 : gimage->ID;
+      
+	            menu_item = gtk_menu_item_new_with_label (menu_item_label);
+	            gtk_callback_add (gtk_menu_item_get_state (menu_item),dialog_image_menu_callback,
+                (gpointer)&ItemData[num_items]);
+	            gtk_container_add (*menu, menu_item);
+	            gtk_widget_show (menu_item);
+      
+	            xfree (menu_item_label);
+	            num_items ++;
+	          }
+        }
+    }
+  else
     {
       menu_item = gtk_menu_item_new_with_label ("none");
       gtk_container_add (*menu, menu_item);
@@ -669,14 +707,14 @@
      gpointer client_data;
      gpointer call_data;
 {
+  _MenuItemData *ItemData;
   AutoDialog dlg;
-  long *data;
 
-  dlg = client_data;
-  data = (long *) dlg->additional_data;
+  ItemData=(_MenuItemData *)client_data;
+  dlg = (AutoDialog) gtk_widget_get_user_data (ItemData->widget);
 
   if (dlg->callback)
-    (* dlg->callback) (dlg->dialog_ID, data[0], dlg->callback_data, &data[1]);
+    (* dlg->callback) (dlg->dialog_ID,ItemData->data[0],dlg->callback_data,&ItemData->data[1]);
 }
 
 static void
--- app/autodialog.h.old	Fri Nov 22 15:46:47 1996
+++ app/autodialog.h	Fri Nov 22 17:21:19 1996
@@ -49,6 +49,7 @@
   int             item_ID;
   int             item_type;
   char            data[32];
+  void           *additional_data;
   AutoDialogItem  parent;
   link_ptr        children;
   GtkWidget      *widget;
OpenPOWER on IntegriCloud