static void
tab_label_style_set_cb (GtkWidget *hbox,
			GtkStyle *previous_style,
			gpointer user_data)
{
	PangoFontMetrics *metrics;
	PangoContext *context;
	GtkWidget *button;
	int char_width, h, w;

	context = gtk_widget_get_pango_context (hbox);
	metrics = pango_context_get_metrics (context,
					     hbox->style->font_desc,
					     pango_context_get_language (context));

	char_width = pango_font_metrics_get_approximate_digit_width (metrics);
	pango_font_metrics_unref (metrics);

	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (hbox),
					   GTK_ICON_SIZE_MENU, &w, &h);

	gtk_widget_set_size_request
		(hbox, TAB_WIDTH_N_CHARS * PANGO_PIXELS(char_width) + 2 * w, -1);

	button = g_object_get_data (G_OBJECT (hbox), "close-button");
	gtk_widget_set_size_request (button, w + 2, h + 2);
}
static void
pluma_spinner_size_request (GtkWidget *widget,
			   GtkRequisition *requisition)
{
	PlumaSpinner *spinner = PLUMA_SPINNER (widget);
	PlumaSpinnerPrivate *priv = spinner->priv;

	if ((priv->need_load &&
	     !pluma_spinner_load_images (spinner)) ||
            priv->images == NULL)
	{
		requisition->width = requisition->height = 0;
		gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
						   priv->size,
						   &requisition->width,
					           &requisition->height);
		return;
	}

	requisition->width = priv->images->width;
	requisition->height = priv->images->height;

	/* FIXME fix this hack */
	/* allocate some extra margin so we don't butt up against toolbar edges */
	if (priv->size != GTK_ICON_SIZE_MENU)
	{
		requisition->width += 2;
		requisition->height += 2;
	}
}
/* We should probably experiment some more with this.
 * Right now the rendered icon is pretty good for most
 * themes. However, the icon is slightly large for themes
 * with large toolbar icons.
 */
static GdkPixbuf *
new_pixbuf_from_widget (GtkWidget *widget)
{
  GtkWidget *window;
  GdkPixbuf *pixbuf;
  gint icon_height;
  GdkScreen *screen;

  screen = gtk_widget_get_screen (widget);

  if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
					  GTK_ICON_SIZE_LARGE_TOOLBAR,
					  NULL,
					  &icon_height))
    {
      icon_height = DEFAULT_ICON_HEIGHT;
    }

  window = gtk_offscreen_window_new ();
  /* Set the width to -1 as we want the separator to be as thin as possible. */
  gtk_widget_set_size_request (widget, -1, icon_height);
  gtk_container_add (GTK_CONTAINER (window), widget);
  gtk_widget_show_all (window);

  /* Process the waiting events to have the widget actually drawn */
  gdk_window_process_updates (gtk_widget_get_window (window), TRUE);
  pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window));
  gtk_widget_destroy (window);

  return pixbuf;
}
Esempio n. 4
0
static void
ephy_spinner_size_request (GtkWidget *widget,
			   GtkRequisition *requisition)
{
	EphySpinner *spinner = EPHY_SPINNER (widget);
	EphySpinnerDetails *details = spinner->details;

	if ((details->need_load &&
	     !ephy_spinner_load_images (spinner)) ||
            details->images == NULL)
	{
		requisition->width = requisition->height = 0;
		gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
						   details->size,
						   &requisition->width,
					           &requisition->height);
		return;
	}

	requisition->width = details->images->width;
	requisition->height = details->images->height;

	/* FIXME fix this hack */
	/* allocate some extra margin so we don't butt up against toolbar edges */
	if (details->size != GTK_ICON_SIZE_MENU)
	{
		requisition->width += 2;
		requisition->height += 2;
	}
}
Esempio n. 5
0
static void
ensure_icon_size (GtkIconHelper *self,
                  GtkStyleContext *context,
		  gint *width_out,
		  gint *height_out)
{
  gint width, height;
  GtkSettings *settings;
  GdkScreen *screen;

  screen = gtk_style_context_get_screen (context);
  settings = gtk_settings_get_for_screen (screen);

  if (self->priv->pixel_size != -1)
    {
      width = height = self->priv->pixel_size;
    }
  else if (!gtk_icon_size_lookup_for_settings (settings,
					       self->priv->icon_size,
					       &width, &height))
    {
      if (self->priv->icon_size == GTK_ICON_SIZE_INVALID)
        {
          width = height = 0;
        }
      else
        {
          g_warning ("Invalid icon size %d\n", self->priv->icon_size);
          width = height = 24;
        }
    }

  *width_out = width;
  *height_out = height;
}
Esempio n. 6
0
static void
button_set_style(GtkWidget * button, GtkStyle * previous_style, gpointer user_data)
{
	gint h, w;

	gtk_icon_size_lookup_for_settings(gtk_widget_get_settings(button), GTK_ICON_SIZE_MENU, &w, &h);

	gtk_widget_set_size_request(button, w + 2, h + 2);
}
Esempio n. 7
0
/**
 * gul_gui_image_set_from_mime_type:
 * @image: a #GtkImage
 * @mime_type: a MIME type
 * @icon_size: a stock icon size
 *
 * Set the @image to display the icon for MIME type @mime_type.  Sample MIME
 * types are "text/plain", "application/ogg".  Sample stock sizes are
 * #GTK_ICON_SIZE_MENU, #GTK_ICON_SIZE_DIALOG.
 */
void
gul_gui_image_set_from_mime_type (GtkWidget  *image,
		                  const char *mime_type,
				  GtkIconSize icon_size)
{
	GtkIconTheme *theme;
	char           *icon;
	GtkIconSource  *source;
	GtkIconSet     *icon_set;

	g_return_if_fail (GTK_IS_IMAGE(image));
	g_return_if_fail (mime_type != NULL);

	theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (image));

	icon = gnome_icon_lookup (theme, NULL, NULL, NULL, NULL,
				  mime_type,
				  GNOME_ICON_LOOKUP_FLAGS_NONE, NULL);

	if (!g_path_is_absolute (icon))
	{
		int   width, height;
		GtkIconInfo *icon_info;

		if (!gtk_icon_size_lookup_for_settings 
			(gtk_widget_get_settings (GTK_WIDGET(image)),
			 icon_size, &width, &height))
		{
			width = height = -1;
		}

		icon_info = gtk_icon_theme_lookup_icon (theme, icon, height,0);
		g_free (icon);

		g_return_if_fail (icon_info != NULL);

		icon = g_strdup (gtk_icon_info_get_filename (icon_info));
		gtk_icon_info_free (icon_info);
	}

	/* Now that we have the icon filename, wrap it into an GtkIconSet so
	 * that we really get the desired size; the icon size in the file may
	 * still be arbitrary, in case of SVG themes, for example.
	 */

	source = gtk_icon_source_new ();
	gtk_icon_source_set_filename (source, icon);
	g_free (icon);

	icon_set = gtk_icon_set_new ();
	gtk_icon_set_add_source (icon_set, source);
	gtk_icon_source_free (source);

	gtk_image_set_from_icon_set (GTK_IMAGE(image), icon_set, icon_size);

	gtk_icon_set_unref (icon_set);
}
/**
 * gtk_clutter_texture_set_from_icon_name:
 * @texture: a #GtkClutterTexture
 * @widget: (allow-none): a #GtkWidget or %NULL
 * @icon_name: the name of the icon
 * @icon_size: the icon size or -1
 * @error: a return location for errors, or %NULL
 *
 * Sets the contents of @texture using the @icon_name from the
 * current icon theme.
 *
 * Return value: %TRUE on success, %FALSE on failure
 *
 * Since: 1.0
 */
gboolean
gtk_clutter_texture_set_from_icon_name (GtkClutterTexture  *texture,
                                        GtkWidget          *widget,
                                        const gchar        *icon_name,
                                        GtkIconSize         icon_size,
                                        GError            **error)
{
  GError *local_error = NULL;
  GtkSettings *settings;
  GtkIconTheme *icon_theme;
  gboolean returnval;
  gint width, height;
  GdkPixbuf *pixbuf;

  g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE);
  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
  g_return_val_if_fail (icon_name != NULL, FALSE);
  g_return_val_if_fail ((icon_size > GTK_ICON_SIZE_INVALID) || (icon_size == -1), FALSE);

  if (widget && gtk_widget_has_screen (widget))
    {
      GdkScreen *screen;

      screen = gtk_widget_get_screen (widget);
      settings = gtk_settings_get_for_screen (screen);
      icon_theme = gtk_icon_theme_get_for_screen (screen);
    }
  else
    {
      settings = gtk_settings_get_default ();
      icon_theme = gtk_icon_theme_get_default ();
    }

  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  if (icon_size == -1 ||
      !gtk_icon_size_lookup_for_settings (settings, icon_size, &width, &height))
    {
      width = height = 48;
    }
  G_GNUC_END_IGNORE_DEPRECATIONS

  pixbuf = gtk_icon_theme_load_icon (icon_theme,
                                     icon_name,
                                     MIN (width, height), 0,
                                     &local_error);
  if (local_error)
    {
      g_propagate_error (error, local_error);
      return FALSE;
    }

  returnval = gtk_clutter_texture_set_from_pixbuf (texture, pixbuf, error);
  g_object_unref (pixbuf);

  return returnval;
}
Esempio n. 9
0
int
_gtk_widget_lookup_for_size (GtkWidget *widget,
                             GtkIconSize icon_size)
{
	int w, h;
	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
					   icon_size,
					   &w, &h);
	return MAX (w, h);
}
Esempio n. 10
0
int
get_folder_pixbuf_size_for_menu (GtkWidget *widget)
{
	int icon_width, icon_height;

	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
					   GTK_ICON_SIZE_MENU,
					   &icon_width, &icon_height);
	return MAX (icon_width, icon_height);
}
Esempio n. 11
0
int
get_folder_pixbuf_size_for_list (GtkWidget *widget)
{
	int icon_width, icon_height;

	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
					   GTK_ICON_SIZE_SMALL_TOOLBAR,
					   &icon_width, &icon_height);
	return MAX (icon_width, icon_height);
}
Esempio n. 12
0
static void
event_box_realize_cb (GtkWidget *widget, GtkImage *icon)
{
  GtkImageType type;

  set_drag_cursor (widget);

  type = gtk_image_get_storage_type (icon);
  if (type == GTK_IMAGE_STOCK)
    {
      gchar *stock_id;
      GdkPixbuf *pixbuf;

      gtk_image_get_stock (icon, &stock_id, NULL);
      pixbuf = gtk_widget_render_icon (widget, stock_id,
	                               GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
      gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
      g_object_unref (pixbuf);
    }
  else if (type == GTK_IMAGE_ICON_NAME)
    {
      const gchar *icon_name;
      GdkScreen *screen;
      GtkIconTheme *icon_theme;
      GtkSettings *settings;
      gint width, height;
      GdkPixbuf *pixbuf;

      gtk_image_get_icon_name (icon, &icon_name, NULL);
      screen = gtk_widget_get_screen (widget);
      icon_theme = gtk_icon_theme_get_for_screen (screen);
      settings = gtk_settings_get_for_screen (screen);

      if (!gtk_icon_size_lookup_for_settings (settings,
                                              GTK_ICON_SIZE_LARGE_TOOLBAR,
					      &width, &height))
        {
	  width = height = 24;
	}

      pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
                                         MIN (width, height), 0, NULL);
      if (G_UNLIKELY (!pixbuf))
        return;

      gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
      g_object_unref (pixbuf);

    }
  else if (type == GTK_IMAGE_PIXBUF)
    {
      GdkPixbuf *pixbuf = gtk_image_get_pixbuf (icon);
      gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
    }
}
Esempio n. 13
0
int
_gtk_icon_get_pixel_size (GtkWidget   *widget,
			  GtkIconSize  size)
{
	int icon_width, icon_height;

	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
					   size,
					   &icon_width, &icon_height);
	return MAX (icon_width, icon_height);
}
Esempio n. 14
0
static int
get_default_icon_size (GtkWidget *widget)
{
	int icon_width, icon_height;

	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
					   GTK_ICON_SIZE_DIALOG,
					   &icon_width, &icon_height);

	return MAX (icon_width, icon_height);
}
Esempio n. 15
0
static int
get_size_in_pixels (GtkWidget   * widget,
                    GtkIconSize   icon_size)
{
    int width, height;

    gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
                                       icon_size,
                                       &width,
                                       &height);
    return MAX (width, height);
}
Esempio n. 16
0
void Gobby::CloseButton::on_style_changed(
	const Glib::RefPtr<Gtk::Style>& previous_style)
#endif
{
	int width;
	int height;

	gtk_icon_size_lookup_for_settings(
		gtk_widget_get_settings(GTK_WIDGET(gobj())),
		GTK_ICON_SIZE_MENU, &width, &height);
	set_size_request(width + 2, height + 2);
}
Esempio n. 17
0
static GtkWidget *
clone_image_menu_size (GtkImage *image, GtkSettings *settings)
{
  GtkImageType storage_type = gtk_image_get_storage_type (image);

  if (storage_type == GTK_IMAGE_STOCK)
    {
      gchar *stock_id;
      gtk_image_get_stock (image, &stock_id, NULL);
      return gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
    }
  else if (storage_type == GTK_IMAGE_ICON_NAME)
    {
      const gchar *icon_name;
      gtk_image_get_icon_name (image, &icon_name, NULL);
      return gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
    }
  else if (storage_type == GTK_IMAGE_ICON_SET)
    {
      GtkIconSet *icon_set;
      gtk_image_get_icon_set (image, &icon_set, NULL);
      return gtk_image_new_from_icon_set (icon_set, GTK_ICON_SIZE_MENU);
    }
  else if (storage_type == GTK_IMAGE_GICON)
    {
      GIcon *icon;
      gtk_image_get_gicon (image, &icon, NULL);
      return gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
    }
  else if (storage_type == GTK_IMAGE_PIXBUF)
    {
      gint width, height;
      
      if (settings &&
	  gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
					     &width, &height))
	{
	  GdkPixbuf *src_pixbuf, *dest_pixbuf;
	  GtkWidget *cloned_image;

	  src_pixbuf = gtk_image_get_pixbuf (image);
	  dest_pixbuf = gdk_pixbuf_scale_simple (src_pixbuf, width, height,
						 GDK_INTERP_BILINEAR);

	  cloned_image = gtk_image_new_from_pixbuf (dest_pixbuf);
	  g_object_unref (dest_pixbuf);

	  return cloned_image;
	}
    }

  return NULL;
}
Esempio n. 18
0
static void
chat_window_close_button_style_set_cb (GtkWidget *button,
				       GtkStyle  *previous_style,
				       gpointer   user_data)
{
	gint h, w;

	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
					   GTK_ICON_SIZE_MENU, &w, &h);

	gtk_widget_set_size_request (button, w, h);
}
static void
gedit_close_button_style_set (GtkWidget *button,
			      GtkStyle *previous_style)
{
	gint h, w;

	gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
					   GTK_ICON_SIZE_MENU, &w, &h);

	gtk_widget_set_size_request (button, w + 2, h + 2);

	GTK_WIDGET_CLASS (gedit_close_button_parent_class)->style_set (button, previous_style);
}
Esempio n. 20
0
void
gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry,
				    GtkIconEntryPosition icon_pos,
				    GIcon *icon)
{
  GdkPixbuf *pixbuf = NULL;
  GtkIconEntryPrivate *priv;
  EntryIconInfo *icon_info;
  GdkScreen *screen;
  GtkIconTheme *icon_theme;
  GtkSettings *settings;
  gint width, height;
  GError *error = NULL;
  GtkIconInfo *info;

  priv = GTK_ICON_ENTRY_GET_PRIVATE (entry);
  icon_info = &priv->icons[icon_pos];

  screen = gtk_widget_get_screen (GTK_WIDGET (entry));
  icon_theme = gtk_icon_theme_get_for_screen (screen);
  settings = gtk_settings_get_for_screen (screen);

  if (icon != NULL)
    {
      gtk_icon_size_lookup_for_settings (settings,
					 GTK_ICON_SIZE_MENU,
					 &width, &height);

      #if #GTK_CHECK_VERSION (2, 14, 0)
      info = gtk_icon_theme_lookup_by_gicon (icon_theme,
					     icon,
					     MIN (width, height), 0);
      #else
      info = NULL;
      #endif
      pixbuf = gtk_icon_info_load_icon (info, &error);
      if (pixbuf == NULL)
	{
	  g_error_free (error);
	  pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
					   GTK_STOCK_MISSING_IMAGE,
					   GTK_ICON_SIZE_MENU,
					   NULL);
	}
    }

  gtk_icon_entry_set_icon_internal ((GtkIconEntry*)entry,
				    icon_pos,
				    pixbuf);
}
Esempio n. 21
0
/**
 * gtk_icon_entry_set_icon_from_icon_name
 * @entry: A #GtkIconEntry;
 * @icon_pos: The position at which to set the icon
 * @icon_name: An icon name
 *
 * Sets the icon shown in the entry at the specified position from the current
 * icon theme.  If the icon name isn't known, a "broken image" icon will be
 * displayed instead.  If the current icon theme is changed, the icon will be
 * updated appropriately.
 */
void
gtk_icon_entry_set_icon_from_icon_name (GtkIconEntry *entry,
					GtkIconEntryPosition icon_pos,
					const gchar *icon_name)
{
  GdkPixbuf *pixbuf = NULL;
  EntryIconInfo *icon_info;
  GtkIconEntryPrivate *priv;
  GdkScreen *screen;
  GtkIconTheme *icon_theme;
  GtkSettings *settings;
  gint width, height;
  GError *error = NULL;

  g_return_if_fail (entry != NULL);
  g_return_if_fail (GTK_IS_ICON_ENTRY (entry));
  g_return_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos));

  priv = GTK_ICON_ENTRY_GET_PRIVATE (entry);
  icon_info = &priv->icons[icon_pos];

  screen = gtk_widget_get_screen (GTK_WIDGET (entry));
  icon_theme = gtk_icon_theme_get_for_screen (screen);
  settings = gtk_settings_get_for_screen (screen);

  if (icon_name != NULL)
    {
      gtk_icon_size_lookup_for_settings (settings,
					 GTK_ICON_SIZE_MENU,
					 &width, &height);

      pixbuf = gtk_icon_theme_load_icon (icon_theme,
					 icon_name,
					 MIN (width, height), 0, &error);

      if (pixbuf == NULL)
	{
	  g_error_free (error);
	  pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry),
					   GTK_STOCK_MISSING_IMAGE,
					   GTK_ICON_SIZE_MENU,
					   NULL);
	}
    }

  gtk_icon_entry_set_icon_internal (entry,
				    icon_pos,
				    pixbuf);
}
Esempio n. 22
0
static void
terminal_tab_label_style_set (GtkWidget *widget,
                              GtkStyle *previous_style)
{
  TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (widget);
  TerminalTabLabelPrivate *priv = tab_label->priv;
  void (* style_set) (GtkWidget *, GtkStyle *) = GTK_WIDGET_CLASS (terminal_tab_label_parent_class)->style_set;
  int h, w;

  if (style_set)
    style_set (widget, previous_style);

  gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
                                     GTK_ICON_SIZE_MENU, &w, &h);
  gtk_widget_set_size_request (priv->close_button, w + 2, h + 2);
}
Esempio n. 23
0
GdkPixbuf *
gui_editor_get_stock_icon (GtkWidget *widget, const gchar *stock_id, GtkIconSize size)
{
  GdkScreen *screen = gtk_widget_get_screen (widget);
  GtkIconTheme *theme = gtk_icon_theme_get_for_screen (screen);
  gint marker_size;
  gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
									 size,
									 NULL,
									 &marker_size);


  GdkPixbuf *pixbuf;
  pixbuf = gtk_icon_theme_load_icon (theme, stock_id, marker_size, 0, NULL);

  return pixbuf;
}
Esempio n. 24
0
static void
gimp_cell_renderer_color_get_size (GtkCellRenderer *cell,
                                   GtkWidget       *widget,
                                   GdkRectangle    *cell_area,
                                   gint            *x_offset,
                                   gint            *y_offset,
                                   gint            *width,
                                   gint            *height)
{
  GimpCellRendererColor *color = GIMP_CELL_RENDERER_COLOR (cell);
  gint                   calc_width;
  gint                   calc_height;

  gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
                                     color->size, &calc_width, &calc_height);

  if (cell_area && calc_width > 0 && calc_height > 0)
    {
      if (x_offset)
        {
          *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
                        1.0 - cell->xalign : cell->xalign) *
                       (cell_area->width - calc_width));
          *x_offset = MAX (*x_offset, 0) + cell->xpad;
        }
      if (y_offset)
        {
          *y_offset = (cell->yalign *
                       (cell_area->height - calc_height));
          *y_offset = MAX (*y_offset, 0) + cell->ypad;
        }
    }
  else
    {
      if (x_offset)
        *x_offset = 0;
      if (y_offset)
        *y_offset = 0;
    }

  if (width)
    *width  = calc_width  + 2 * cell->xpad;
  if (height)
    *height = calc_height + 2 * cell->ypad;
}
Esempio n. 25
0
static void
gimp_procedure_action_connect_proxy (GtkAction *action,
                                     GtkWidget *proxy)
{
  GimpProcedureAction *procedure_action = GIMP_PROCEDURE_ACTION (action);

  GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy);

  if (GTK_IS_IMAGE_MENU_ITEM (proxy) && procedure_action->procedure)
    {
      GdkPixbuf *pixbuf;

      g_object_get (procedure_action->procedure,
                    "icon-pixbuf", &pixbuf,
                    NULL);

      if (pixbuf)
        {
          GtkSettings *settings = gtk_widget_get_settings (proxy);
          gint         width;
          gint         height;
          GtkWidget   *image;

          gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
                                             &width, &height);

          if (width  != gdk_pixbuf_get_width  (pixbuf) ||
              height != gdk_pixbuf_get_height (pixbuf))
            {
              GdkPixbuf *copy;

              copy = gdk_pixbuf_scale_simple (pixbuf, width, height,
                                              GDK_INTERP_BILINEAR);
              g_object_unref (pixbuf);
              pixbuf = copy;
            }

          image = gtk_image_new_from_pixbuf (pixbuf);
          gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), image);
          g_object_unref (pixbuf);
        }
    }
}
Esempio n. 26
0
static GtkWidget *
gimp_container_box_get_preview (GimpDocked   *docked,
                                GimpContext  *context,
                                GtkIconSize   size)
{
  GimpContainerBox  *box  = GIMP_CONTAINER_BOX (docked);
  GimpContainerView *view = GIMP_CONTAINER_VIEW (docked);
  GimpContainer     *container;
  GtkWidget         *preview;
  gint               width;
  gint               height;
  gint               border_width = 1;
  const gchar       *prop_name;

  container = gimp_container_view_get_container (view);

  g_return_val_if_fail (container != NULL, NULL);

  gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (GTK_WIDGET (box)),
                                     size, &width, &height);

  prop_name = gimp_context_type_to_prop_name (container->children_type);

  preview = gimp_prop_view_new (G_OBJECT (context), prop_name,
                                context, height);
  GIMP_VIEW (preview)->renderer->size = -1;

  gimp_container_view_get_view_size (view, &border_width);

  border_width = MIN (1, border_width);

  gimp_view_renderer_set_size_full (GIMP_VIEW (preview)->renderer,
                                    width, height, border_width);

  return preview;
}
Esempio n. 27
0
static void
menu_style_set_cb (GtkWidget *menu, GtkStyle *old_style,
                   ShellStatusMenu *status)
{
  ShellStatusMenuPrivate *priv = status->priv;
  GtkSettings *settings;
  int width;
  int height;

  priv->icon_size = gtk_icon_size_from_name ("panel-menu");
  if (priv->icon_size == GTK_ICON_SIZE_INVALID)
    priv->icon_size = gtk_icon_size_register ("panel-menu", 24, 24);

  if (gtk_widget_has_screen (menu))
    settings = gtk_settings_get_for_screen (gtk_widget_get_screen (menu));
  else
    settings = gtk_settings_get_default ();

  if (!gtk_icon_size_lookup_for_settings (settings, priv->icon_size, &width,
      &height))
    priv->pixel_size = -1;
  else
    priv->pixel_size = MAX(width, height);
}
Esempio n. 28
0
/**************************************************************************
  Creates a new dialog. It will be a tab or a window depending on the
  current user setting of 'gui_gtk3_enable_tabs'.
  Sets pdlg to point to the dialog once it is create, Zeroes pdlg on
  dialog destruction.
  user_data will be passed through response function
  check_top indicates if the layout deision should depend on the parent.
**************************************************************************/
void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook,
                    gpointer user_data, bool check_top)
{
  struct gui_dialog *dlg;
  GtkWidget *vbox, *action_area;
  static int dialog_id_counter;

  dlg = fc_malloc(sizeof(*dlg));
  dialog_list = g_list_prepend(dialog_list, dlg);

  dlg->source = pdlg;
  *pdlg = dlg;
  dlg->user_data = user_data;
  dlg->title = NULL;
  
  dlg->default_width = 200;
  dlg->default_height = 300;

  if (gui_gtk3_enable_tabs) {
    dlg->type = GUI_DIALOG_TAB;
  } else {
    dlg->type = GUI_DIALOG_WINDOW;
  }

  if (!gui_action) {
    gui_action = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL);
  }
  dlg->gui_button = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);

  vbox = gtk_grid_new();
  action_area = gtk_grid_new();
  gtk_grid_set_row_spacing(GTK_GRID(action_area), 4);
  gtk_grid_set_column_spacing(GTK_GRID(action_area), 4);
  if (gui_gtk3_enable_tabs &&
      (check_top && notebook != GTK_NOTEBOOK(top_notebook))
      && !gui_gtk3_small_display_layout) {
    /* We expect this to be short (as opposed to tall); maximise usable
     * height by putting buttons down the right hand side */
    gtk_orientable_set_orientation(GTK_ORIENTABLE(action_area),
                                   GTK_ORIENTATION_VERTICAL);
  } else {
    /* We expect this to be reasonably tall; maximise usable width by
     * putting buttons along the bottom */
    gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox),
                                   GTK_ORIENTATION_VERTICAL);
  }

  gtk_widget_show(vbox);
  gtk_container_add(GTK_CONTAINER(vbox), action_area);
  gtk_widget_show(action_area);

  gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
  gtk_container_set_border_width(GTK_CONTAINER(action_area), 2);

  switch (dlg->type) {
  case GUI_DIALOG_WINDOW:
    {
      GtkWidget *window;

      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_widget_set_name(window, "Freeciv");
      gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
      setup_dialog(window, toplevel);

      gtk_container_add(GTK_CONTAINER(window), vbox);
      dlg->v.window = window;
      g_signal_connect(window, "delete_event",
        G_CALLBACK(gui_dialog_delete_handler), dlg);
      
    }
    break;
  case GUI_DIALOG_TAB:
    {
      GtkWidget *hbox, *label, *image, *button, *event_box;
      gint w, h;
      gchar *buf;

      gtk_icon_size_lookup_for_settings(
        gtk_settings_get_for_screen(gtk_widget_get_screen(vbox)),
        GTK_ICON_SIZE_MENU, &w, &h);

      hbox = gtk_grid_new();

      label = gtk_label_new(NULL);
      gtk_widget_set_halign(label, GTK_ALIGN_START);
      gtk_widget_set_valign(label, GTK_ALIGN_CENTER);
      gtk_widget_set_margin_left(label, 4);
      gtk_widget_set_margin_right(label, 4);
      gtk_widget_set_margin_top(label, 0);
      gtk_widget_set_margin_bottom(label, 0);
      gtk_container_add(GTK_CONTAINER(hbox), label);

      button = gtk_button_new();
      gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
      g_signal_connect_swapped(button, "clicked",
	  G_CALLBACK(gui_dialog_delete_tab_handler), dlg);

      buf = g_strdup_printf(_("Close Tab:\n%s"), _("Ctrl+W"));
      gtk_widget_set_tooltip_text(button, buf);
      g_free(buf);

      image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
      gtk_widget_set_margin_left(image, 0);
      gtk_widget_set_margin_right(image, 0);
      gtk_widget_set_margin_top(image, 0);
      gtk_widget_set_margin_bottom(image, 0);
      gtk_button_set_image(GTK_BUTTON(button), image);

      gtk_container_add(GTK_CONTAINER(hbox), button);

      gtk_widget_show_all(hbox);

      event_box = gtk_event_box_new();
      gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE);
      gtk_container_add(GTK_CONTAINER(event_box), hbox);

      gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, event_box);
      dlg->v.tab.handler_id =
	g_signal_connect(notebook, "switch-page",
	    G_CALLBACK(gui_dialog_switch_page_handler), dlg);
      dlg->v.tab.child = vbox;

      dlg->v.tab.label = label;
      dlg->v.tab.notebook = GTK_WIDGET(notebook);
      
      gtk_widget_add_events(event_box, GDK_BUTTON2_MOTION_MASK);
      g_signal_connect(event_box, "button-press-event",
                       G_CALLBACK(click_on_tab_callback), dlg);
    }
    break;
  }

  dlg->vbox = vbox;
  dlg->action_area = action_area;

  dlg->response_callback = gui_dialog_destroyed;
  
  dlg->id = dialog_id_counter;
  dialog_id_counter++;
  dlg->return_dialog_id = -1;

  g_signal_connect(vbox, "destroy",
      G_CALLBACK(gui_dialog_destroy_handler), dlg);
  g_signal_connect(vbox, "key_press_event",
      G_CALLBACK(gui_dialog_key_press_handler), dlg);

  g_object_set_data(G_OBJECT(vbox), "gui-dialog-data", dlg);
}
static void
configure_item_cursor (GtkToolItem *item,
		       EggEditableToolbar *etoolbar)
{
  EggEditableToolbarPrivate *priv = etoolbar->priv;
  GtkWidget *widget = GTK_WIDGET (item);

  if (gtk_widget_get_window (widget) != NULL)
    {
      if (priv->edit_mode > 0)
        {
          GdkCursor *cursor;
	  GdkScreen *screen;
          GdkPixbuf *pixbuf = NULL;

	  screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar));

          cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
					       GDK_HAND2);
          gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
          gdk_cursor_unref (cursor);

          gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
                               G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
          if (GTK_IS_SEPARATOR_TOOL_ITEM (item))
            {
              pixbuf = new_separator_pixbuf ();
            }
          else
            {
              char *icon_name=NULL;
              char *stock_id=NULL;
              GtkAction *action;
              char *name;

              name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
              action = name ? find_action (etoolbar, name) : NULL;

              if (action)
                {
                   g_object_get (action,
                                 "icon-name", &icon_name,
                                 "stock-id", &stock_id,
                                 NULL);
                }
              if (icon_name)
                {
                  GdkScreen *screen;
                  GtkIconTheme *icon_theme;
                  GtkSettings *settings;
                  gint width, height;

                  screen = gtk_widget_get_screen (widget);
                  icon_theme = gtk_icon_theme_get_for_screen (screen);
                  settings = gtk_settings_get_for_screen (screen);

                  if (!gtk_icon_size_lookup_for_settings (settings,
                                                          GTK_ICON_SIZE_LARGE_TOOLBAR,
                                                          &width, &height))
                    {
                      width = height = 24;
                    }

                  pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
                                                     MIN (width, height), 0, NULL);
                }
              else if (stock_id)
                {
                  pixbuf = gtk_widget_render_icon (widget, stock_id,
	                                           GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
                }
              g_free (icon_name);
              g_free (stock_id);
            }

          if (G_UNLIKELY (!pixbuf))
            {
              return;
            }
          gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
          g_object_unref (pixbuf);

        }
      else
        {
          gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET(item)), NULL);
        }
    }
}
Esempio n. 30
0
static void
gimp_controller_list_init (GimpControllerList *list)
{
  GtkWidget         *hbox;
  GtkWidget         *sw;
  GtkWidget         *tv;
  GtkTreeViewColumn *column;
  GtkCellRenderer   *cell;
  GtkWidget         *vbox;
  GtkWidget         *image;
  GtkIconSize        icon_size;
  gint               icon_width;
  gint               icon_height;
  GType             *controller_types;
  guint              n_controller_types;
  gint               i;

  gtk_orientable_set_orientation (GTK_ORIENTABLE (list),
                                  GTK_ORIENTATION_VERTICAL);

  list->gimp = NULL;

  list->hbox = hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_box_pack_start (GTK_BOX (list), hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
                                       GTK_SHADOW_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0);
  gtk_widget_show (sw);

  list->src = gtk_list_store_new (N_COLUMNS,
                                  G_TYPE_STRING,
                                  G_TYPE_STRING,
                                  G_TYPE_GTYPE);
  tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list->src));
  g_object_unref (list->src);

  gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (tv), FALSE);

  column = gtk_tree_view_column_new ();
  gtk_tree_view_column_set_title (column, _("Available Controllers"));
  gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);

  cell = gtk_cell_renderer_pixbuf_new ();
  gtk_tree_view_column_pack_start (column, cell, FALSE);
  gtk_tree_view_column_set_attributes (column, cell,
                                       "icon-name", COLUMN_ICON,
                                       NULL);

  g_object_get (cell, "stock-size", &icon_size, NULL);

  cell = gtk_cell_renderer_text_new ();
  gtk_tree_view_column_pack_start (column, cell, TRUE);
  gtk_tree_view_column_set_attributes (column, cell,
                                       "text", COLUMN_NAME,
                                       NULL);

  gtk_container_add (GTK_CONTAINER (sw), tv);
  gtk_widget_show (tv);

  g_signal_connect_object (tv, "row-activated",
                           G_CALLBACK (gimp_controller_list_row_activated),
                           G_OBJECT (list), 0);

  list->src_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
  gtk_tree_selection_set_mode (list->src_sel, GTK_SELECTION_BROWSE);

  g_signal_connect_object (list->src_sel, "changed",
                           G_CALLBACK (gimp_controller_list_src_sel_changed),
                           G_OBJECT (list), 0);

  controller_types = g_type_children (GIMP_TYPE_CONTROLLER,
                                      &n_controller_types);

  for (i = 0; i < n_controller_types; i++)
    {
      GimpControllerClass *controller_class;
      GtkTreeIter          iter;

      controller_class = g_type_class_ref (controller_types[i]);

      gtk_list_store_append (list->src, &iter);
      gtk_list_store_set (list->src, &iter,
                          COLUMN_ICON, controller_class->icon_name,
                          COLUMN_NAME, controller_class->name,
                          COLUMN_TYPE, controller_types[i],
                          -1);

      g_type_class_unref (controller_class);
    }

  g_free (controller_types);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);

  list->add_button = gtk_button_new ();
  gtk_box_pack_start (GTK_BOX (vbox), list->add_button, TRUE, FALSE, 0);
  gtk_widget_set_sensitive (list->add_button, FALSE);
  gtk_widget_show (list->add_button);

  image = gtk_image_new_from_icon_name ("go-next",
                                        GTK_ICON_SIZE_BUTTON);
  gtk_container_add (GTK_CONTAINER (list->add_button), image);
  gtk_widget_show (image);

  g_signal_connect (list->add_button, "clicked",
                    G_CALLBACK (gimp_controller_list_add_clicked),
                    list);

  g_object_add_weak_pointer (G_OBJECT (list->add_button),
                             (gpointer) &list->add_button);

  list->remove_button = gtk_button_new ();
  gtk_box_pack_start (GTK_BOX (vbox), list->remove_button, TRUE, FALSE, 0);
  gtk_widget_set_sensitive (list->remove_button, FALSE);
  gtk_widget_show (list->remove_button);

  image = gtk_image_new_from_icon_name ("go-previous",
                                        GTK_ICON_SIZE_BUTTON);
  gtk_container_add (GTK_CONTAINER (list->remove_button), image);
  gtk_widget_show (image);

  g_signal_connect (list->remove_button, "clicked",
                    G_CALLBACK (gimp_controller_list_remove_clicked),
                    list);

  g_object_add_weak_pointer (G_OBJECT (list->remove_button),
                             (gpointer) &list->remove_button);

  gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (GTK_WIDGET (list)),
                                     icon_size, &icon_width, &icon_height);

  list->dest = gimp_container_tree_view_new (NULL, NULL, icon_height, 0);
  gimp_container_tree_view_set_main_column_title (GIMP_CONTAINER_TREE_VIEW (list->dest),
                                                  _("Active Controllers"));
  gtk_tree_view_set_headers_visible (GIMP_CONTAINER_TREE_VIEW (list->dest)->view,
                                     TRUE);
  gtk_box_pack_start (GTK_BOX (list->hbox), list->dest, TRUE, TRUE, 0);
  gtk_widget_show (list->dest);

  g_signal_connect_object (list->dest, "select-item",
                           G_CALLBACK (gimp_controller_list_select_item),
                           G_OBJECT (list), 0);
  g_signal_connect_object (list->dest, "activate-item",
                           G_CALLBACK (gimp_controller_list_activate_item),
                           G_OBJECT (list), 0);

  list->edit_button =
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
                            "document-properties",
                            _("Configure the selected controller"),
                            NULL,
                            G_CALLBACK (gimp_controller_list_edit_clicked),
                            NULL,
                            list);
  list->up_button =
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
                            "go-up",
                            _("Move the selected controller up"),
                            NULL,
                            G_CALLBACK (gimp_controller_list_up_clicked),
                            NULL,
                            list);
  list->down_button =
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
                            "go-down",
                            _("Move the selected controller down"),
                            NULL,
                            G_CALLBACK (gimp_controller_list_down_clicked),
                            NULL,
                            list);

  gtk_widget_set_sensitive (list->edit_button, FALSE);
  gtk_widget_set_sensitive (list->up_button,   FALSE);
  gtk_widget_set_sensitive (list->down_button, FALSE);
}