+ gint i;
+ gchar *text;
+ static struct /* just an unnamed struct */
+ {
+ gchar *target_prefix;
+ gint target_prefix_len;
+ } ignore_targets[] = {
+ { "application/x-openoffice", -1 },
+ { NULL, 0 } /* mark end */
+ },
+ *ptr ;
+
+
+ /*
+ * If there is not text in targets then return
+ */
+ if ( gtk_targets_include_text( atoms, n_atoms ) == FALSE )
+ return;
+
+ /*
+ * init ignore target if it's needed
+ */
+ if ( ignore_targets->target_prefix_len < 0 )
+ {
+ ptr = ignore_targets;
+
+ while( ptr->target_prefix )
+ {
+ ptr->target_prefix_len = strlen( ptr->target_prefix );
+ ptr++;
+ }
+ }
+
+ /*
+ * checks all avaliable targets for presence of ignorable
+ * targets ( which come from "wrong" applications )
+ */
+ for(i=0;i<n_atoms;i++)
+ {
+ gchar *target_name = gdk_atom_name( atoms[i] );
+
+ if (!target_name)
+ continue;
+
+ ptr = ignore_targets;
+
+ while( ptr->target_prefix )
+ {
+ if ( strncmp( target_name, ptr->target_prefix, ptr->target_prefix_len ) == 0 )
+ {
+ /*
+ * It's found a ignorable targets - we will not accept text to
+ * prevent unexpected and surprised behaviour of X-selection
+ */
+ g_free(target_name);
+ return;
+ }
+
+ g_free(target_name);
+ ptr++;
+ }
+ }
+
+ /*
+ * Ok - selection has text, selection is not owned to strange application -
+ * request contents
+ */
+ text = gtk_clipboard_wait_for_text(clipboard);
+ /* be carefull - world has a lot of unexpected events :) */
+ if (text)
+ addMenuItem( (ClipboardDescr*)data, text );