コード例 #1
0
ファイル: sexy-icon-entry.c プロジェクト: ib/xarchiver
/**
 * sexy_icon_entry_add_clear_button
 * @icon_entry: A #SexyIconEntry.
 *
 * A convenience function to add a clear button to the end of the entry.
 * This is useful for search boxes.
 */
void
sexy_icon_entry_add_clear_button(SexyIconEntry *icon_entry,
								 gpointer data,
								 gpointer function)
{
	GtkWidget *icon;

	g_return_if_fail(icon_entry != NULL);
	g_return_if_fail(SEXY_IS_ICON_ENTRY(icon_entry));

	icon = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
	gtk_widget_show(icon);
	sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(icon_entry),
							 SEXY_ICON_ENTRY_SECONDARY,
							 GTK_IMAGE(icon));
	sexy_icon_entry_set_icon_highlight(SEXY_ICON_ENTRY(icon_entry),
									   SEXY_ICON_ENTRY_SECONDARY, TRUE);

	if (icon_entry->priv->icon_released_id != 0)
	{
		g_signal_handler_disconnect(icon_entry,
									icon_entry->priv->icon_released_id);
	}

	icon_entry->priv->icon_released_id =
		g_signal_connect(G_OBJECT(icon_entry), "icon_released",
						 G_CALLBACK(function), data);
}
コード例 #2
0
ファイル: sexy-icon-entry.c プロジェクト: egroeper/referencer
/**
 * sexy_icon_entry_get_icon
 * @entry: A #SexyIconEntry.
 * @position: Icon position.
 *
 * Retrieves the image used for the icon
 *
 * Returns: A #GtkImage.
 */
GtkImage *
sexy_icon_entry_get_icon(const SexyIconEntry *entry,
						 SexyIconEntryPosition icon_pos)
{
	g_return_val_if_fail(entry != NULL, NULL);
	g_return_val_if_fail(SEXY_IS_ICON_ENTRY(entry), NULL);
	g_return_val_if_fail(IS_VALID_ICON_ENTRY_POSITION(icon_pos), NULL);

	return entry->priv->icons[icon_pos].icon;
}
コード例 #3
0
ファイル: sexy-icon-entry.c プロジェクト: ib/xarchiver
/**
 * sexy_icon_entry_get_icon_highlight
 * @entry: A #SexyIconEntry.
 * @position: Icon position.
 *
 * Retrieves whether entry will highlight the icon on mouseover.
 *
 * Returns: TRUE if icon highlights.
 */
gboolean
sexy_icon_entry_get_icon_highlight(const SexyIconEntry *entry,
								   SexyIconEntryPosition icon_pos)
{
	g_return_val_if_fail(entry != NULL, FALSE);
	g_return_val_if_fail(SEXY_IS_ICON_ENTRY(entry), FALSE);
	g_return_val_if_fail(IS_VALID_ICON_ENTRY_POSITION(icon_pos), FALSE);

	return entry->priv->icons[icon_pos].highlight;
}
コード例 #4
0
ファイル: sexy-icon-entry.c プロジェクト: ib/xarchiver
/**
 * sexy_icon_entry_set_icon
 * @entry: A #SexyIconEntry.
 * @position: Icon position.
 * @icon: A #GtkImage to set as the icon.
 *
 * Sets the icon shown in the entry
 */
void
sexy_icon_entry_set_icon(SexyIconEntry *entry, SexyIconEntryPosition icon_pos,
						 GtkImage *icon)
{
	SexyIconInfo *icon_info;

	g_return_if_fail(entry != NULL);
	g_return_if_fail(SEXY_IS_ICON_ENTRY(entry));
	g_return_if_fail(IS_VALID_ICON_ENTRY_POSITION(icon_pos));
	g_return_if_fail(icon == NULL || GTK_IS_IMAGE(icon));

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

	if (icon == icon_info->icon)
		return;

	if (icon_pos == SEXY_ICON_ENTRY_SECONDARY &&
		entry->priv->icon_released_id != 0)
	{
		g_signal_handler_disconnect(entry, entry->priv->icon_released_id);
		entry->priv->icon_released_id = 0;
	}

	if (icon == NULL)
	{
		if (icon_info->icon != NULL)
		{
			gtk_widget_destroy(GTK_WIDGET(icon_info->icon));
			icon_info->icon = NULL;

			/*
			 * Explicitly check, as the pointer may become invalidated
			 * during destruction.
			 */
			if (icon_info->window != NULL && GDK_IS_WINDOW(icon_info->window))
				gdk_window_hide(icon_info->window);
		}
	}
	else
	{
		if (icon_info->window != NULL && icon_info->icon == NULL)
			gdk_window_show(icon_info->window);

		g_signal_connect(G_OBJECT(icon), "notify",
						 G_CALLBACK(update_icon), entry);

		icon_info->icon = icon;
		g_object_ref(icon);
	}

	update_icon(NULL, NULL, entry);
}
コード例 #5
0
ファイル: sexy-icon-entry.c プロジェクト: ib/xarchiver
static void
sexy_icon_entry_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
	g_return_if_fail(SEXY_IS_ICON_ENTRY(widget));
	g_return_if_fail(allocation != NULL);

	widget->allocation = *allocation;

	GTK_WIDGET_CLASS(parent_class)->size_allocate(widget, allocation);

	if (GTK_WIDGET_REALIZED(widget))
		place_windows(SEXY_ICON_ENTRY(widget), allocation);
}
コード例 #6
0
ファイル: sexy-icon-entry.c プロジェクト: ib/xarchiver
static void
sexy_icon_entry_finalize(GObject *obj)
{
	SexyIconEntry *entry;

	g_return_if_fail(obj != NULL);
	g_return_if_fail(SEXY_IS_ICON_ENTRY(obj));

	entry = SEXY_ICON_ENTRY(obj);

	g_free(entry->priv);

	if (G_OBJECT_CLASS(parent_class)->finalize)
		G_OBJECT_CLASS(parent_class)->finalize(obj);
}
コード例 #7
0
ファイル: sexy-icon-entry.c プロジェクト: ib/xarchiver
/**
 * sexy_icon_entry_set_icon_highlight
 * @entry: A #SexyIconEntry;
 * @position: Icon position.
 * @highlight: TRUE if the icon should highlight on mouse-over
 *
 * Determines whether the icon will highlight on mouse-over.
 */
void
sexy_icon_entry_set_icon_highlight(SexyIconEntry *entry,
								   SexyIconEntryPosition icon_pos,
								   gboolean highlight)
{
	SexyIconInfo *icon_info;

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

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

	if (icon_info->highlight == highlight)
		return;

	icon_info->highlight = highlight;
}
コード例 #8
0
ファイル: sexy-icon-entry.c プロジェクト: ib/xarchiver
static gint
sexy_icon_entry_expose(GtkWidget *widget, GdkEventExpose *event)
{
	SexyIconEntry *entry;

	g_return_val_if_fail(SEXY_IS_ICON_ENTRY(widget), FALSE);
	g_return_val_if_fail(event != NULL, FALSE);

	entry = SEXY_ICON_ENTRY(widget);

	if (GTK_WIDGET_DRAWABLE(widget))
	{
		gboolean found = FALSE;
		int i;

		for (i = 0; i < MAX_ICONS && !found; i++)
		{
			SexyIconInfo *icon_info = &entry->priv->icons[i];

			if (event->window == icon_info->window)
			{
				gint width;
				GtkAllocation text_area_alloc;

				get_text_area_size(entry, &text_area_alloc);
				gdk_drawable_get_size(icon_info->window, &width, NULL);

				gtk_paint_flat_box(widget->style, icon_info->window,
								   GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
								   NULL, widget, "entry_bg",
								   0, 0, width, text_area_alloc.height);

				draw_icon(widget, i);

				found = TRUE;
			}
		}

		if (!found)
			GTK_WIDGET_CLASS(parent_class)->expose_event(widget, event);
	}

	return FALSE;
}