return found_widget;
}
+/**
+ * Returns a label widget that is made selectable (i.e. the user can copy the text)
+ * @param text String to display - maybe NULL
+ * @return The label widget
+ */
+GtkWidget* ui_label_new_selectable ( const gchar* text )
+{
+ GtkWidget *widget = gtk_label_new ( text );
+ gtk_label_set_selectable ( GTK_LABEL(widget), TRUE );
+ return widget;
+}
+
/**
* Apply the alpha value to the specified pixbuf
*/
for (iii = 0; iii < width; iii++) for (jjj = 0; jjj < height; jjj++)
{
pixels += 3;
- *pixels++ = alpha;
+ if ( *pixels != 0 )
+ *pixels = alpha;
+ pixels++;
+ }
+ return pixbuf;
+}
+
+
+/**
+ * Reduce the alpha value of the specified pixbuf by alpha / 255
+ */
+GdkPixbuf *ui_pixbuf_scale_alpha ( GdkPixbuf *pixbuf, guint8 alpha )
+{
+ guchar *pixels;
+ gint width, height, iii, jjj;
+
+ if ( ! gdk_pixbuf_get_has_alpha ( pixbuf ) )
+ {
+ GdkPixbuf *tmp = gdk_pixbuf_add_alpha(pixbuf,FALSE,0,0,0);
+ g_object_unref(G_OBJECT(pixbuf));
+ pixbuf = tmp;
+ if ( !pixbuf )
+ return NULL;
+ }
+
+ pixels = gdk_pixbuf_get_pixels(pixbuf);
+ width = gdk_pixbuf_get_width(pixbuf);
+ height = gdk_pixbuf_get_height(pixbuf);
+
+ /* r,g,b,a,r,g,b,a.... */
+ for (iii = 0; iii < width; iii++) for (jjj = 0; jjj < height; jjj++)
+ {
+ pixels += 3;
+ if ( *pixels != 0 )
+ *pixels = (guint8)(((guint16)*pixels * (guint16)alpha) / 255);
+ pixels++;
}
return pixbuf;
}
+
+
+
+/**
+ *
+ */
+void ui_add_recent_file ( const gchar *filename )
+{
+ if ( filename ) {
+ GtkRecentManager *manager = gtk_recent_manager_get_default();
+ GFile *file = g_file_new_for_commandline_arg ( filename );
+ gchar *uri = g_file_get_uri ( file );
+ if ( uri && manager )
+ gtk_recent_manager_add_item ( manager, uri );
+ g_object_unref( file );
+ g_free (uri);
+ }
+}
+
+/**
+ * Clear the entry text if the specified icon is pressed
+ */
+static void ui_icon_clear_entry ( GtkEntry *entry,
+ GtkEntryIconPosition position,
+ GdkEventButton *event,
+ gpointer data )
+{
+ if ( position == GPOINTER_TO_INT(data) )
+ gtk_entry_set_text ( entry, "" );
+}
+
+static void
+text_changed_cb (GtkEntry *entry,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ if ( data ) {
+ gboolean has_text = gtk_entry_get_text_length(entry) > 0;
+ gtk_entry_set_icon_sensitive ( entry, GPOINTER_TO_INT(data), has_text );
+ }
+}
+
+/**
+ * Create an entry field with an icon to clear the entry
+ *
+ * Ideal for entries used for getting user entered transitory data,
+ * so it is easy to delete the text and start again.
+ */
+GtkWidget *ui_entry_new ( const gchar *str, GtkEntryIconPosition position )
+{
+ GtkWidget *entry = gtk_entry_new();
+ if ( str )
+ gtk_entry_set_text ( GTK_ENTRY(entry), str );
+ gtk_entry_set_icon_from_stock ( GTK_ENTRY(entry), position, GTK_STOCK_CLEAR );
+#if GTK_CHECK_VERSION (2,20,0)
+ text_changed_cb ( GTK_ENTRY(entry), NULL, GINT_TO_POINTER(position) );
+ g_signal_connect ( entry, "notify::text", G_CALLBACK(text_changed_cb), GINT_TO_POINTER(position) );
+#endif
+ g_signal_connect ( entry, "icon-release", G_CALLBACK(ui_icon_clear_entry), GINT_TO_POINTER(position) );
+ return entry;
+}
+
+/**
+ * Create a spinbutton with an icon to clear the entry
+ *
+ * Ideal for entries used for getting user entered transitory data,
+ * so it is easy to delete the number and start again.
+ */
+GtkWidget *ui_spin_button_new ( GtkAdjustment *adjustment,
+ gdouble climb_rate,
+ guint digits )
+{
+ GtkWidget *spin = gtk_spin_button_new ( adjustment, climb_rate, digits );
+ gtk_entry_set_icon_from_stock ( GTK_ENTRY(spin), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_CLEAR );
+ g_signal_connect ( spin, "icon-release", G_CALLBACK(ui_icon_clear_entry), GINT_TO_POINTER(GTK_ENTRY_ICON_PRIMARY) );
+ return spin;
+}