Primary/secondary icon resizing in GtkEntry



Title: Samsung Enterprise Portal mySingle

 

Hi All ,

 

In GTK+ 3.8..x primary and secondary icon cannot be resized in GtkEntry .

The size of icon is always remain 16 x 16 .

I raised a bug on bugzilla for this issue .

https://bugzilla.gnome.org/show_bug.cgi?id=710600

In the above bug report I also provided the fix. I implemented new API in GtkEntry so that application developer can resize the dimension from application.

 

Before patch :

gtk_entry_set_icon_from_pixbuf API is used for setting primary/secondary  icon in GtkEntry , but icon is always set of dimension of GTK_ICON_SIZE_MENU ( 16 x 16 ).

 

After Patch :

I implemented new API "gtk_entry_set_icon_from_pixbuf_at_size" so that user can change the size to any desired dimension .

 

void gtk_entry_set_icon_from_pixbuf_at_size (           GtkEntry             *entry,
                                                                                   GtkEntryIconPosition icon_pos,
                                                                                  GdkPixbuf            *pixbuf,
                                                                                  GtkIconSize          icon_size )

{
  GtkEntryPrivate *priv;
  EntryIconInfo *icon_info;
  g_return_if_fail (GTK_IS_ENTRY (entry));
  g_return_if_fail (IS_VALID_ICON_POSITION (icon_pos));

  priv = entry->priv;

  if ((icon_info = priv->icons[icon_pos]) == NULL)
    icon_info = construct_icon_info (GTK_WIDGET (entry), icon_pos);

  g_object_freeze_notify (G_OBJECT (entry));

  if (pixbuf)
    g_object_ref (pixbuf);

  gtk_entry_clear (entry, icon_pos);

  if (pixbuf)
    {

        _gtk_icon_helper_set_pixbuf (icon_info->icon_helper, pixbuf);
        _gtk_icon_helper_set_icon_size (icon_info->icon_helper,
                                        icon_size );

/* Icon size is passed from application */

      if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
        {
          g_object_notify (G_OBJECT (entry), "primary-icon-pixbuf");
          g_object_notify (G_OBJECT (entry), "primary-icon-storage-type");
        }
      else
        {
          g_object_notify (G_OBJECT (entry), "secondary-icon-pixbuf");
          g_object_notify (G_OBJECT (entry), "secondary-icon-storage-type");
        }

      if (gtk_widget_get_mapped (GTK_WIDGET (entry)))
          gdk_window_show_unraised (icon_info->window);

      g_object_unref (pixbuf);
    }

  if (gtk_widget_get_visible (GTK_WIDGET (entry)))
    gtk_widget_queue_resize (GTK_WIDGET (entry));

  g_object_thaw_notify (G_OBJECT (entry));
}

 

Usage of API in application code :

int main( int argc,

char *argv[] )

{

gtk_init (&argc, &argv);

GtkBuilder *builder = gtk_builder_new ();

gtk_builder_add_from_file (builder, "icon.glade", NULL);

window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));

gtk_entry1 = GTK_WIDGET (gtk_builder_get_object (builder, "entry1"));

gtk_entry2 = GTK_WIDGET (gtk_builder_get_object (builder, "entry2"));

pixbuf_entry1 = gdk_pixbuf_new_from_file("primary_icon.png", NULL);

pixbuf_entry2 = gdk_pixbuf_new_from_file("secondary_icon.png", NULL );

pixbuf_entry3 = gdk_pixbuf_new_from_file("primary_icon.png" , NULL);

pixbuf_entry4 = gdk_pixbuf_new_from_file("secondary_icon.png" ,NULL);

 

/* Creating icon size of varied dimension */

GtkIconSize GTK_ICON_SIZE_1_PRIMARY = gtk_icon_size_register ( "gtk-1-primary" , 16 , 16 );

GtkIconSize GTK_ICON_SIZE_1_SECONDARY = gtk_icon_size_register ( "gtk-2-secondary" , 83 , 53 );

GtkIconSize GTK_ICON_SIZE_2_PRIMARY = gtk_icon_size_register ( "gtk-1-primary" , 35 , 35 );

GtkIconSize GTK_ICON_SIZE_2_SECONDARY = gtk_icon_size_register ( "gtk-2-secondary" , 55 , 35 );

 

gtk_entry_set_icon_from_pixbuf_at_size (GTK_ENTRY(gtk_entry1),GTK_ENTRY_ICON_PRIMARY, pixbuf_entry1,GTK_ICON_SIZE_1_PRIMARY );

gtk_entry_set_icon_from_pixbuf_at_size (GTK_ENTRY(gtk_entry1),GTK_ENTRY_ICON_SECONDARY,pixbuf_entry2,GTK_ICON_SIZE_1_SECONDARY );

gtk_entry_set_icon_from_pixbuf_at_size (GTK_ENTRY(gtk_entry2),GTK_ENTRY_ICON_PRIMARY, pixbuf_entry3,GTK_ICON_SIZE_2_PRIMARY );

gtk_entry_set_icon_from_pixbuf_at_size (GTK_ENTRY(gtk_entry2),GTK_ENTRY_ICON_SECONDARY,pixbuf_entry4,GTK_ICON_SIZE_2_SECONDARY );

gtk_widget_show_all (window);

 

gtk_main ();

return 0;

}

 

Please review the patch.

 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]