Example #1
0
void wxTaskBarIcon::Private::size_allocate(int width, int height)
{
    int size = height;
    EggTrayIcon* icon = EGG_TRAY_ICON(m_eggTrayIcon);
    if (egg_tray_icon_get_orientation(icon) == GTK_ORIENTATION_VERTICAL)
        size = width;
    if (m_size == size)
        return;
    m_size = size;
    int w = m_bitmap.GetWidth();
    int h = m_bitmap.GetHeight();
    if (w > size || h > size)
    {
        if (w > size) w = size;
        if (h > size) h = size;
        GdkPixbuf* pixbuf =
            gdk_pixbuf_scale_simple(m_bitmap.GetPixbuf(), w, h, GDK_INTERP_BILINEAR);
        GtkImage* image = GTK_IMAGE(gtk_bin_get_child(GTK_BIN(m_eggTrayIcon)));
        gtk_image_set_from_pixbuf(image, pixbuf);
        g_object_unref(pixbuf);
    }
}
Example #2
0
static void
egg_status_icon_size_allocate (EggStatusIcon *status_icon,
			       GtkAllocation *allocation)
{
  GtkOrientation orientation;
  gint size;
  gboolean alloc_changed = FALSE;

  orientation = egg_tray_icon_get_orientation (EGG_TRAY_ICON (status_icon->priv->tray_icon));

  if (orientation == GTK_ORIENTATION_HORIZONTAL)
    size = allocation->height;
  else
    size = allocation->width;
  
  if ((status_icon->priv->alloc_height != allocation->height) ||
       (status_icon->priv->alloc_width != allocation->width))
  {
    status_icon->priv->alloc_height = allocation->height;
    status_icon->priv->alloc_width = allocation->width;
    alloc_changed = TRUE;
  }
  
  if (status_icon->priv->size != size)
    {
      status_icon->priv->size = size;
      g_object_notify (G_OBJECT (status_icon), "size");
      emit_size_changed_signal (status_icon, size);
      alloc_changed = TRUE;
    }
    
    if (alloc_changed)
    {
      egg_status_icon_update_image (status_icon);
    }
}
Example #3
0
static void
egg_status_icon_update_image (EggStatusIcon *status_icon)
{
  if (status_icon->priv->blink_off)
    {
      gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image),
				 egg_status_icon_blank_icon (status_icon));
      return;
    }

  switch (status_icon->priv->image_type)
    {
    case GTK_IMAGE_PIXBUF:
      {
	GdkPixbuf *pixbuf;

	pixbuf = status_icon->priv->image_data.pixbuf;

	if (pixbuf)
	  {
	    GdkPixbuf *scaled;
	    gint size;
	    gint width;
	    gint height;

	    size = status_icon->priv->size;

	    width  = gdk_pixbuf_get_width  (pixbuf);
	    height = gdk_pixbuf_get_height (pixbuf);

	    if (width > size || height > size)
	      {
                scaled = gdk_pixbuf_scale_simple (pixbuf,
                                                        MIN (size, width),
                                                        MIN (size, height),
                                                        GDK_INTERP_BILINEAR);
	      }
	    else
              {
                scaled = g_object_ref (pixbuf);
              }

	    gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), scaled);

            /* Sets the icon's transparency mask as the window's shape mask.
               Note: This doesn't handle translucency (partial transparency). */
            gint image_offset_x, image_offset_y;
            /* No way to know the image's real offset but by calculating ourselves. */
            {
              GtkOrientation orientation;
              gfloat xalign, yalign;
              gint xpad, ypad;
              GtkWidget* image = status_icon->priv->image;
              gtk_misc_get_padding(GTK_MISC(image), &xpad, &ypad);
              gtk_misc_get_alignment(GTK_MISC(image), &xalign, &yalign);
              /* We're aligning either horizontally or vertically, depending
                 on the orientation. According to this, we'll assume either
                 width or height to be preallocated up to the panel's size. */
              orientation = egg_tray_icon_get_orientation (EGG_TRAY_ICON (status_icon->priv->tray_icon));
              /* We base on the code found in gtk_image_expose */
              image_offset_x = floor(image->allocation.x + xpad + ((status_icon->priv->alloc_width - image->requisition.width) * xalign) + 0.5);
              image_offset_y = floor(image->allocation.y + ypad + ((status_icon->priv->alloc_height - image->requisition.height) * yalign) + 0.5);
            }
            GdkBitmap* scaled_mask = NULL;
            gdk_pixbuf_render_pixmap_and_mask(scaled, NULL, &scaled_mask, 0);
            if (scaled_mask)
            {
               /* It's only possible to set shape masks on real windows, so we have to set an offseted shape mask. */
               gtk_widget_shape_combine_mask(GTK_WIDGET(status_icon->priv->tray_icon), scaled_mask, image_offset_x, image_offset_y);
               g_object_unref(scaled_mask);
            }
	    
	    g_object_unref (scaled);
	  }
	else
	  {
	    gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), NULL);
	  }
      }
      break;
    case GTK_IMAGE_STOCK:
    case GTK_IMAGE_ANIMATION:
    case GTK_IMAGE_EMPTY:
      gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), NULL);
      break;
    default:
      g_assert_not_reached ();
      break;
    }
    
}