summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Estrugo <ramiro@src.gnome.org>2000-08-21 14:16:54 +0000
committerRamiro Estrugo <ramiro@src.gnome.org>2000-08-21 14:16:54 +0000
commit7050528710fd6fe7356901636c317559fb31a807 (patch)
treefbfbf68e2bd00b062a97595b8519b9260054aeb6
parent0198de152d4fda376c817deab02382ef03c72279 (diff)
downloadnautilus-7050528710fd6fe7356901636c317559fb31a807.tar.gz
Tasks: 1612, 1274, 1511 and 1588.
* libnautilus-extensions/nautilus-scalable-font.c: * libnautilus-extensions/nautilus-scalable-font.h: New GtkObject subclass that provdes a simple interface to raph's librsvg FreeType2 bases anti aliased text rendering. * libnautilus-extensions/nautilus-font-picker.c: * libnautilus-extensions/nautilus-font-picker.h: New font picker class. I will soon use it in the preferences dialog instead of the current one. * libnautilus-extensions/nautilus-buffered-widget.c: * libnautilus-extensions/nautilus-buffered-widget.h: New virtual widget class that encapsulates the details of finding a suitable background for compositing pixbufs. * libnautilus-extensions/nautilus-image.c: * libnautilus-extensions/nautilus-image.h: Rewritten NautilusImage class. Took out all the label stuff, which lives in its own class. Now subclassed from NautilusBufferedWidget so that background the image gets composited on is always correct and groks NautilusBackground. * libnautilus-extensions/nautilus-label.c: * libnautilus-extensions/nautilus-label.h: New NautilusLabel widget class. A label widget that is capable of displaying anti aliased text composited over a complex background. The background can be installed as NautilusBackground on a NautilusLabel widget or any of its ancestors. The best background will automatically be found and used by the widget. * services/nautilus-dependant-shared/shared-service-widgets.c, * services/nautilus-dependant-shared/shared-service-widgets.h, * services/startup/nautilus-view/nautilus-service-startup-view.c: Update for changes in the NautilusImage api. Unfortunately, these components are slightly broken now cause of the NautilusImage changes. I will fix them shortly. * libnautilus-extensions/nautilus-string-map.c: * libnautilus-extensions/nautilus-string-map.h: New simple class to map an arbitrary number of strings to a single string. * libnautilus-extensions/nautilus-lib-self-check-functions.h: Add tests for the new string map class. * libnautilus-extensions/Makefile.am: Build the new widgets. Also add some depedencies on the static libraries we link into this beast. This way, libnautilus-extensions will rebuild of one if its dependency static libs is touched. * test/.cvsignore, * test/Makefile.am, * test/test-nautilus-font-picker.c, * test/test-nautilus-font.c, * test/test-nautilus-image.c, * test/test-nautilus-label.c: Update test programs for new widgets.
-rw-r--r--ChangeLog73
-rw-r--r--components/services/nautilus-dependant-shared/shared-service-widgets.c79
-rw-r--r--components/services/nautilus-dependant-shared/shared-service-widgets.h3
-rw-r--r--components/services/startup/nautilus-view/nautilus-service-startup-view.c6
-rw-r--r--libnautilus-extensions/Makefile.am36
-rw-r--r--libnautilus-extensions/nautilus-buffered-widget.c668
-rw-r--r--libnautilus-extensions/nautilus-buffered-widget.h87
-rw-r--r--libnautilus-extensions/nautilus-font-picker.c497
-rw-r--r--libnautilus-extensions/nautilus-font-picker.h80
-rw-r--r--libnautilus-extensions/nautilus-image.c1314
-rw-r--r--libnautilus-extensions/nautilus-image.h105
-rw-r--r--libnautilus-extensions/nautilus-label.c569
-rw-r--r--libnautilus-extensions/nautilus-label.h102
-rw-r--r--libnautilus-extensions/nautilus-lib-self-check-functions.h5
-rw-r--r--libnautilus-extensions/nautilus-scalable-font.c1056
-rw-r--r--libnautilus-extensions/nautilus-scalable-font.h138
-rw-r--r--libnautilus-extensions/nautilus-string-map.c295
-rw-r--r--libnautilus-extensions/nautilus-string-map.h46
-rw-r--r--libnautilus-private/Makefile.am36
-rw-r--r--libnautilus-private/nautilus-buffered-widget.c668
-rw-r--r--libnautilus-private/nautilus-buffered-widget.h87
-rw-r--r--libnautilus-private/nautilus-font-picker.c497
-rw-r--r--libnautilus-private/nautilus-font-picker.h80
-rw-r--r--libnautilus-private/nautilus-image.c1314
-rw-r--r--libnautilus-private/nautilus-image.h105
-rw-r--r--libnautilus-private/nautilus-label.c569
-rw-r--r--libnautilus-private/nautilus-label.h102
-rw-r--r--libnautilus-private/nautilus-lib-self-check-functions.h5
-rw-r--r--libnautilus-private/nautilus-scalable-font.c1056
-rw-r--r--libnautilus-private/nautilus-scalable-font.h138
-rw-r--r--libnautilus-private/nautilus-string-map.c295
-rw-r--r--libnautilus-private/nautilus-string-map.h46
-rw-r--r--test/.cvsignore5
-rw-r--r--test/Makefile.am22
-rw-r--r--test/test-nautilus-font-picker.c55
-rw-r--r--test/test-nautilus-font.c77
-rw-r--r--test/test-nautilus-image.c766
-rw-r--r--test/test-nautilus-label.c677
38 files changed, 8839 insertions, 2920 deletions
diff --git a/ChangeLog b/ChangeLog
index ff8e1c322..cef10e881 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,78 @@
2000-08-21 Ramiro Estrugo <ramiro@eazel.com>
+ Tasks: 1612, 1274, 1511 and 1588.
+
+ * libnautilus-extensions/nautilus-scalable-font.c:
+ * libnautilus-extensions/nautilus-scalable-font.h:
+
+ New GtkObject subclass that provdes a simple interface to raph's
+ librsvg FreeType2 bases anti aliased text rendering.
+
+ * libnautilus-extensions/nautilus-font-picker.c:
+ * libnautilus-extensions/nautilus-font-picker.h:
+
+ New font picker class. I will soon use it in the preferences
+ dialog instead of the current one.
+
+ * libnautilus-extensions/nautilus-buffered-widget.c:
+ * libnautilus-extensions/nautilus-buffered-widget.h:
+
+ New virtual widget class that encapsulates the details of finding
+ a suitable background for compositing pixbufs.
+
+ * libnautilus-extensions/nautilus-image.c:
+ * libnautilus-extensions/nautilus-image.h:
+
+ Rewritten NautilusImage class. Took out all the label stuff,
+ which lives in its own class. Now subclassed from
+ NautilusBufferedWidget so that background the image gets
+ composited on is always correct and groks NautilusBackground.
+
+ * libnautilus-extensions/nautilus-label.c:
+ * libnautilus-extensions/nautilus-label.h:
+
+ New NautilusLabel widget class. A label widget that is capable of
+ displaying anti aliased text composited over a complex background.
+
+ The background can be installed as NautilusBackground on a
+ NautilusLabel widget or any of its ancestors. The best background
+ will automatically be found and used by the widget.
+
+ * services/nautilus-dependant-shared/shared-service-widgets.c,
+ * services/nautilus-dependant-shared/shared-service-widgets.h,
+ * services/startup/nautilus-view/nautilus-service-startup-view.c:
+
+ Update for changes in the NautilusImage api. Unfortunately, these
+ components are slightly broken now cause of the NautilusImage
+ changes. I will fix them shortly.
+
+ * libnautilus-extensions/nautilus-string-map.c:
+ * libnautilus-extensions/nautilus-string-map.h:
+
+ New simple class to map an arbitrary number of strings to a single
+ string.
+
+ * libnautilus-extensions/nautilus-lib-self-check-functions.h:
+ Add tests for the new string map class.
+
+ * libnautilus-extensions/Makefile.am:
+
+ Build the new widgets. Also add some depedencies on the static
+ libraries we link into this beast. This way,
+ libnautilus-extensions will rebuild of one if its dependency
+ static libs is touched.
+
+ * test/.cvsignore,
+ * test/Makefile.am,
+ * test/test-nautilus-font-picker.c,
+ * test/test-nautilus-font.c,
+ * test/test-nautilus-image.c,
+ * test/test-nautilus-label.c:
+
+ Update test programs for new widgets.
+
+2000-08-21 Ramiro Estrugo <ramiro@eazel.com>
+
* libnautilus-extensions/nautilus-background.c:
(nautilus_widget_has_attached_background):
* libnautilus-extensions/nautilus-background.h:
diff --git a/components/services/nautilus-dependant-shared/shared-service-widgets.c b/components/services/nautilus-dependant-shared/shared-service-widgets.c
index e7275fda7..da45c0e21 100644
--- a/components/services/nautilus-dependant-shared/shared-service-widgets.c
+++ b/components/services/nautilus-dependant-shared/shared-service-widgets.c
@@ -41,13 +41,12 @@
/* Ramiro's very cool generic image widget */
GtkWidget*
create_image_widget (const char *icon_name,
- const char *background_color_spec,
- NautilusImagePlacementType placement) {
-
+ const char *background_color_spec)
+{
char *path;
GtkWidget *image;
GdkPixbuf *pixbuf;
- guint32 background_rgb;
+/* guint32 background_rgb;*/
g_return_val_if_fail (icon_name != NULL, NULL);
g_return_val_if_fail (background_color_spec != NULL, NULL);
@@ -67,15 +66,13 @@ create_image_widget (const char *icon_name,
g_warning ("Could not find the requested icon.");
}
- nautilus_image_set_background_type (NAUTILUS_IMAGE (image),
- NAUTILUS_IMAGE_BACKGROUND_SOLID);
-
- background_rgb = nautilus_parse_rgb_with_white_default (background_color_spec);
+/* nautilus_image_set_background_type (NAUTILUS_IMAGE (image),*/
+/* NAUTILUS_IMAGE_BACKGROUND_SOLID);*/
- nautilus_image_set_background_color (NAUTILUS_IMAGE (image),
- background_rgb);
+/* background_rgb = nautilus_parse_rgb_with_white_default (background_color_spec);*/
- nautilus_image_set_placement_type (NAUTILUS_IMAGE (image), placement);
+/* nautilus_image_set_background_color (NAUTILUS_IMAGE (image),*/
+/* background_rgb);*/
return image;
@@ -90,33 +87,30 @@ create_services_title_widget (const char *title_text) {
GtkWidget *logo_image;
GtkWidget *filler_image;
GtkWidget *text_image;
- GdkFont *font;
+/* GdkFont *font;*/
g_assert (title_text != NULL);
title_hbox = gtk_hbox_new (FALSE, 0);
logo_image = create_image_widget ("eazel-services-logo.png",
- SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR,
- NAUTILUS_IMAGE_PLACEMENT_CENTER);
+ SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR);
filler_image = create_image_widget ("eazel-services-logo-tile.png",
- SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR,
- NAUTILUS_IMAGE_PLACEMENT_TILE);
+ SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR);
text_image = create_image_widget ("eazel-services-logo-tile.png",
- SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR,
- NAUTILUS_IMAGE_PLACEMENT_TILE);
+ SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR);
- font = nautilus_font_factory_get_font_by_family ("helvetica", 20);
+/* font = nautilus_font_factory_get_font_by_family ("helvetica", 20);*/
- nautilus_image_set_label_text (NAUTILUS_IMAGE (text_image), title_text);
- nautilus_image_set_label_font (NAUTILUS_IMAGE (text_image), font);
- nautilus_image_set_extra_width (NAUTILUS_IMAGE (text_image), 8);
- nautilus_image_set_right_offset (NAUTILUS_IMAGE (text_image), 8);
- nautilus_image_set_top_offset (NAUTILUS_IMAGE (text_image), 3);
+/* nautilus_image_set_label_text (NAUTILUS_IMAGE (text_image), title_text); */
+/* nautilus_image_set_label_font (NAUTILUS_IMAGE (text_image), font); */
+/* nautilus_image_set_extra_width (NAUTILUS_IMAGE (text_image), 8);*/
+/* nautilus_image_set_right_offset (NAUTILUS_IMAGE (text_image), 8);*/
+/* nautilus_image_set_top_offset (NAUTILUS_IMAGE (text_image), 3);*/
- gdk_font_unref (font);
+/* gdk_font_unref (font);*/
gtk_widget_show (logo_image);
gtk_widget_show (filler_image);
@@ -140,7 +134,7 @@ create_services_header_widget (const char *left_text,
GtkWidget *left_image;
GtkWidget *right_image;
GtkWidget *filler_image;
- GdkFont *font;
+/* GdkFont *font;*/
g_assert (left_text != NULL);
g_assert (right_text != NULL);
@@ -148,34 +142,31 @@ create_services_header_widget (const char *left_text,
title_hbox = gtk_hbox_new (FALSE, 0);
left_image = create_image_widget ("eazel-services-logo-tile.png",
- SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR,
- NAUTILUS_IMAGE_PLACEMENT_TILE);
+ SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR);
filler_image = create_image_widget ("eazel-services-logo-tile.png",
- SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR,
- NAUTILUS_IMAGE_PLACEMENT_TILE);
+ SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR);
right_image = create_image_widget ("eazel-services-logo-tile.png",
- SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR,
- NAUTILUS_IMAGE_PLACEMENT_TILE);
+ SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR);
- font = nautilus_font_factory_get_font_by_family ("helvetica", 18);
+/* font = nautilus_font_factory_get_font_by_family ("helvetica", 18);*/
- nautilus_image_set_label_text (NAUTILUS_IMAGE (left_image), left_text);
- nautilus_image_set_label_font (NAUTILUS_IMAGE (left_image), font);
+/* nautilus_image_set_label_text (NAUTILUS_IMAGE (left_image), left_text); */
+/* nautilus_image_set_label_font (NAUTILUS_IMAGE (left_image), font); */
- nautilus_image_set_extra_width (NAUTILUS_IMAGE (left_image), 8);
- nautilus_image_set_left_offset (NAUTILUS_IMAGE (left_image), 8);
- nautilus_image_set_top_offset (NAUTILUS_IMAGE (left_image), 1);
+/* nautilus_image_set_extra_width (NAUTILUS_IMAGE (left_image), 8);*/
+/* nautilus_image_set_left_offset (NAUTILUS_IMAGE (left_image), 8);*/
+/* nautilus_image_set_top_offset (NAUTILUS_IMAGE (left_image), 1);*/
- nautilus_image_set_label_text (NAUTILUS_IMAGE (right_image), right_text);
- nautilus_image_set_label_font (NAUTILUS_IMAGE (right_image), font);
+/* nautilus_image_set_label_text (NAUTILUS_IMAGE (right_image), right_text); */
+/* nautilus_image_set_label_font (NAUTILUS_IMAGE (right_image), font); */
- nautilus_image_set_extra_width (NAUTILUS_IMAGE (right_image), 8);
- nautilus_image_set_right_offset (NAUTILUS_IMAGE (right_image), 8);
- nautilus_image_set_top_offset (NAUTILUS_IMAGE (right_image), 1);
+/* nautilus_image_set_extra_width (NAUTILUS_IMAGE (right_image), 8);*/
+/* nautilus_image_set_right_offset (NAUTILUS_IMAGE (right_image), 8);*/
+/* nautilus_image_set_top_offset (NAUTILUS_IMAGE (right_image), 1);*/
- gdk_font_unref (font);
+/* gdk_font_unref (font);*/
gtk_widget_show (left_image);
gtk_widget_show (filler_image);
diff --git a/components/services/nautilus-dependant-shared/shared-service-widgets.h b/components/services/nautilus-dependant-shared/shared-service-widgets.h
index 87f270ea5..5c78fddaa 100644
--- a/components/services/nautilus-dependant-shared/shared-service-widgets.h
+++ b/components/services/nautilus-dependant-shared/shared-service-widgets.h
@@ -33,8 +33,7 @@
#define SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR "rgb:FFFF/FFFF/FFFF"
GtkWidget* create_image_widget (const char *icon_name,
- const char *background_color_spec,
- NautilusImagePlacementType placement);
+ const char *background_color_spec);
GtkWidget* create_services_title_widget (const char *title_text);
GtkWidget* create_services_header_widget (const char *left_text,
const char *right_text);
diff --git a/components/services/startup/nautilus-view/nautilus-service-startup-view.c b/components/services/startup/nautilus-view/nautilus-service-startup-view.c
index 4b8a29a1a..7b7985ec1 100644
--- a/components/services/startup/nautilus-view/nautilus-service-startup-view.c
+++ b/components/services/startup/nautilus-view/nautilus-service-startup-view.c
@@ -106,8 +106,7 @@ generate_startup_form (NautilusServiceStartupView *view)
gtk_widget_show (temp_box);
temp_widget = create_image_widget ("service-watch.png",
- STARTUP_VIEW_DEFAULT_BACKGROUND_COLOR,
- NAUTILUS_IMAGE_PLACEMENT_CENTER);
+ STARTUP_VIEW_DEFAULT_BACKGROUND_COLOR);
g_assert (temp_widget != NULL);
gtk_box_pack_start (GTK_BOX (temp_box), temp_widget, 0, 0, 8);
@@ -174,8 +173,7 @@ generate_form_logo (NautilusServiceStartupView *view) {
gtk_box_pack_start (GTK_BOX (view->details->form), logo_container, 0, 0, 4);
logo_widget = create_image_widget ("startup-logo.png",
- STARTUP_VIEW_DEFAULT_BACKGROUND_COLOR,
- NAUTILUS_IMAGE_PLACEMENT_CENTER);
+ STARTUP_VIEW_DEFAULT_BACKGROUND_COLOR);
g_assert (logo_widget != NULL);
diff --git a/libnautilus-extensions/Makefile.am b/libnautilus-extensions/Makefile.am
index 91da8cd95..91732d5db 100644
--- a/libnautilus-extensions/Makefile.am
+++ b/libnautilus-extensions/Makefile.am
@@ -21,11 +21,15 @@ INCLUDES = \
-DNAUTILUS_DATADIR=\""$(datadir)/nautilus"\" \
$(NULL)
-libnautilus_extensions_la_LDFLAGS= \
+dependency_static_libs =\
$(top_builddir)/cut-n-paste-code/widgets/e-paned/libe-paned.la \
$(top_builddir)/cut-n-paste-code/widgets/nautilus-druid/libnautilus-druid.la \
$(top_builddir)/librsvg/librsvg.la \
$(top_builddir)/cut-n-paste-code/freetype/libfreetype2.la \
+ $(NULL)
+
+libnautilus_extensions_la_LDFLAGS= \
+ $(dependency_static_libs) \
$(GNOME_LIBS) \
$(GNOMECANVASPIXBUF_LIBS) \
$(OAF_LIBS) \
@@ -44,6 +48,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-background.c \
nautilus-bonobo-extensions.c \
nautilus-bookmark.c \
+ nautilus-buffered-widget.c \
nautilus-caption-table.c \
nautilus-caption.c \
nautilus-debug.c \
@@ -58,6 +63,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-file-utilities.c \
nautilus-file.c \
nautilus-font-factory.c \
+ nautilus-font-picker.c \
nautilus-gdk-extensions.c \
nautilus-gdk-pixbuf-extensions.c \
nautilus-generous-bin.c \
@@ -74,6 +80,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-icon-text-item.c \
nautilus-image.c \
nautilus-keep-last-vertical-box.c \
+ nautilus-label.c \
nautilus-lib-self-check-functions.c \
nautilus-link-set.c \
nautilus-link.c \
@@ -91,23 +98,25 @@ libnautilus_extensions_la_SOURCES = \
nautilus-program-chooser.c \
nautilus-program-choosing.c \
nautilus-radio-button-group.c \
+ nautilus-scalable-font.c \
nautilus-search-bar-criterion.c \
nautilus-search-uri.c \
nautilus-self-checks.c \
nautilus-stock-dialogs.c \
nautilus-string-list.c \
+ nautilus-string-map.c \
nautilus-string-picker.c \
nautilus-string.c \
nautilus-text-caption.c \
- nautilus-trash-directory.c \
nautilus-theme.c \
+ nautilus-trash-directory.c \
nautilus-undo-context.c \
nautilus-undo-manager.c \
nautilus-undo-signal-handlers.c \
nautilus-user-level-manager.c \
+ nautilus-vfs-directory.c \
nautilus-view-identifier.c \
nautilus-volume-monitor.c \
- nautilus-vfs-directory.c \
nautilus-xml-extensions.c \
$(NULL)
@@ -118,24 +127,26 @@ noinst_HEADERS = \
nautilus-background.h \
nautilus-bonobo-extensions.h \
nautilus-bookmark.h \
- nautilus-caption.h \
+ nautilus-buffered-widget.h \
nautilus-caption-table.h \
+ nautilus-caption.h \
nautilus-cdrom-extensions.h \
nautilus-debug.h \
nautilus-default-file-icon.h \
nautilus-directory-background.h \
- nautilus-directory.h \
nautilus-directory-metafile.h \
nautilus-directory-notify.h \
nautilus-directory-private.h \
+ nautilus-directory.h \
nautilus-drag.h \
nautilus-entry.h \
nautilus-file-attributes.h \
nautilus-file-changes-queue.h \
- nautilus-file.h \
nautilus-file-private.h \
nautilus-file-utilities.h \
+ nautilus-file.h \
nautilus-font-factory.h \
+ nautilus-font-picker.h \
nautilus-gdk-extensions.h \
nautilus-gdk-pixbuf-extensions.h \
nautilus-generous-bin.h \
@@ -155,9 +166,10 @@ noinst_HEADERS = \
nautilus-image.h \
nautilus-iso9660.h \
nautilus-keep-last-vertical-box.h \
+ nautilus-label.h \
nautilus-lib-self-check-functions.h \
- nautilus-link.h \
nautilus-link-set.h \
+ nautilus-link.h \
nautilus-list-column-title.h \
nautilus-list.h \
nautilus-metadata.h \
@@ -167,20 +179,22 @@ noinst_HEADERS = \
nautilus-preferences-box.h \
nautilus-preferences-dialog.h \
nautilus-preferences-group.h \
- nautilus-preferences.h \
nautilus-preferences-item.h \
nautilus-preferences-pane.h \
+ nautilus-preferences.h \
nautilus-program-chooser.h \
nautilus-program-choosing.h \
nautilus-radio-button-group.h \
+ nautilus-scalable-font.h \
+ nautilus-search-bar-criterion-private.h \
nautilus-search-bar-criterion.h \
nautilus-search-uri.h \
- nautilus-search-bar-criterion-private.h \
nautilus-self-checks.h \
nautilus-stock-dialogs.h \
- nautilus-string.h \
nautilus-string-list.h \
+ nautilus-string-map.h \
nautilus-string-picker.h \
+ nautilus-string.h \
nautilus-text-caption.h \
nautilus-theme.h \
nautilus-trash-directory.h \
@@ -193,3 +207,5 @@ noinst_HEADERS = \
nautilus-volume-monitor.h \
nautilus-xml-extensions.h \
$(NULL)
+
+$(lib_LTLIBRARIES): $(dependency_static_libs)
diff --git a/libnautilus-extensions/nautilus-buffered-widget.c b/libnautilus-extensions/nautilus-buffered-widget.c
new file mode 100644
index 000000000..e568b278d
--- /dev/null
+++ b/libnautilus-extensions/nautilus-buffered-widget.c
@@ -0,0 +1,668 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-buffered-widget.h - A buffered widget for alpha compositing.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+#include "nautilus-buffered-widget.h"
+
+#include "nautilus-gtk-macros.h"
+#include "nautilus-gdk-extensions.h"
+#include "nautilus-gdk-pixbuf-extensions.h"
+#include "nautilus-gtk-extensions.h"
+#include "nautilus-glib-extensions.h"
+#include "nautilus-string.h"
+#include "nautilus-background.h"
+
+#include <gtk/gtksignal.h>
+
+#include <librsvg/rsvg-ft.h>
+
+#include <libart_lgpl/art_misc.h>
+#include <libart_lgpl/art_rect.h>
+#include <libart_lgpl/art_alphagamma.h>
+#include <libart_lgpl/art_affine.h>
+
+#include <librsvg/art_render.h>
+#include <librsvg/art_render_mask.h>
+
+#include <math.h>
+#include <string.h>
+#include <png.h>
+
+/* Arguments */
+enum
+{
+ ARG_0,
+ ARG_BACKGROUND_COLOR,
+ ARG_BACKGROUND_TYPE,
+ ARG_BUFFERED_WIDGET,
+ ARG_PLACEMENT_TYPE,
+};
+
+/* Detail member struct */
+struct _NautilusBufferedWidgetDetail
+{
+ GdkGC *copy_area_gc;
+ GdkPixbuf *buffer_pixbuf;
+ GdkPixbuf *tile_pixbuf;
+};
+
+/* GdkGC refcounting macros */ \
+#define NAUTILUS_GDK_GC_UNREF_IF(_gc) \
+NAUTILUS_MACRO_BEGIN \
+ if ((_gc) != NULL) { \
+ gdk_gc_unref (_gc); \
+ (_gc) = NULL; \
+ } \
+NAUTILUS_MACRO_END
+
+#define NAUTILUS_GDK_GC_REF_IF(_gc) \
+NAUTILUS_MACRO_BEGIN \
+ if ((_gc) != NULL) { \
+ gdk_gc_ref (_gc); \
+ } \
+NAUTILUS_MACRO_END
+
+/* GtkObjectClass methods */
+static void nautilus_buffered_widget_initialize_class (NautilusBufferedWidgetClass *buffered_widget_class);
+static void nautilus_buffered_widget_initialize (NautilusBufferedWidget *buffered_widget);
+static void nautilus_buffered_widget_destroy (GtkObject *object);
+static void nautilus_buffered_widget_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+static void nautilus_buffered_widget_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+
+/* GtkWidgetClass methods */
+static void nautilus_buffered_widget_realize (GtkWidget *widget);
+static void nautilus_buffered_widget_draw (GtkWidget *widget,
+ GdkRectangle *area);
+static void nautilus_buffered_widget_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+
+/* GtkWidgetClass event methods */
+static gint nautilus_buffered_widget_expose (GtkWidget *widget,
+ GdkEventExpose *event);
+/* Private NautilusBufferedWidget things */
+static void background_appearance_changed_callback (NautilusBackground *background,
+ gpointer callback_data);
+static GdkPixbuf* buffered_widget_create_pixbuf_from_background (const NautilusBufferedWidget *buffered_widget,
+ GdkGC *gc);
+static void buffered_widget_update_pixbuf (NautilusBufferedWidget *buffered_widget);
+static GtkWidget *nautilus_gtk_widget_find_background_ancestor (GtkWidget *widget);
+static void nautilus_gdk_pixbuf_tile_alpha (GdkPixbuf *pixbuf,
+ const GdkPixbuf *tile_pixbuf,
+ guint tile_width,
+ guint tile_height,
+ gint tile_origin_x,
+ gint tile_origin_y,
+ GdkInterpType interpolation_mode,
+ guchar overall_alpha);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusBufferedWidget, nautilus_buffered_widget, GTK_TYPE_MISC)
+
+/* Class init methods */
+static void
+nautilus_buffered_widget_initialize_class (NautilusBufferedWidgetClass *buffered_widget_class)
+{
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (buffered_widget_class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (buffered_widget_class);
+
+ /* GtkObjectClass */
+ object_class->destroy = nautilus_buffered_widget_destroy;
+ object_class->set_arg = nautilus_buffered_widget_set_arg;
+ object_class->get_arg = nautilus_buffered_widget_get_arg;
+
+ /* GtkWidgetClass */
+ widget_class->realize = nautilus_buffered_widget_realize;
+ widget_class->draw = nautilus_buffered_widget_draw;
+ widget_class->expose_event = nautilus_buffered_widget_expose;
+ widget_class->size_allocate = nautilus_buffered_widget_size_allocate;
+
+ /* NautilusBufferedWidgetClass */
+ buffered_widget_class->render_buffer_pixbuf = NULL;
+}
+
+void
+nautilus_buffered_widget_initialize (NautilusBufferedWidget *buffered_widget)
+{
+ GTK_WIDGET_UNSET_FLAGS (buffered_widget, GTK_CAN_FOCUS);
+
+ GTK_WIDGET_SET_FLAGS (buffered_widget, GTK_NO_WINDOW);
+
+ buffered_widget->detail = g_new (NautilusBufferedWidgetDetail, 1);
+
+ buffered_widget->detail->copy_area_gc = NULL;
+ buffered_widget->detail->buffer_pixbuf = NULL;
+ buffered_widget->detail->tile_pixbuf = NULL;
+}
+
+/* GtkObjectClass methods */
+static void
+nautilus_buffered_widget_destroy (GtkObject *object)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (object));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (object);
+
+ NAUTILUS_GDK_GC_UNREF_IF (buffered_widget->detail->copy_area_gc);
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->buffer_pixbuf);
+ buffered_widget->detail->buffer_pixbuf = NULL;
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->tile_pixbuf);
+ buffered_widget->detail->tile_pixbuf = NULL;
+ NAUTILUS_GDK_GC_UNREF_IF (buffered_widget->detail->copy_area_gc);
+
+ g_free (buffered_widget->detail);
+
+ /* Chain destroy */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static void
+nautilus_buffered_widget_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (object));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (object);
+
+#if 0
+ switch (arg_id)
+ {
+ case ARG_PLACEMENT_TYPE:
+ buffered_widget->detail->placement_type = GTK_VALUE_ENUM (*arg);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+#endif
+}
+
+static void
+nautilus_buffered_widget_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (object));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (object);
+
+#if 0
+ switch (arg_id)
+ {
+ case ARG_PLACEMENT_TYPE:
+ GTK_VALUE_ENUM (*arg) = buffered_widget->detail->placement_type;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+#endif
+}
+
+/* GtkWidgetClass methods */
+static void
+nautilus_buffered_widget_realize (GtkWidget *widget)
+{
+ GtkWidget *background_ancestor;
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (widget));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (widget);
+
+ /* Chain realize */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, realize, (widget));
+
+ /* Create GCs */
+ buffered_widget->detail->copy_area_gc = nautilus_gdk_create_copy_area_gc (widget->window);
+
+ background_ancestor = nautilus_gtk_widget_find_background_ancestor (widget);
+
+ if (background_ancestor != NULL) {
+ NautilusBackground *background;
+
+ background = nautilus_get_widget_background (background_ancestor);
+ g_assert (NAUTILUS_IS_BACKGROUND (background));
+
+ gtk_signal_connect (GTK_OBJECT (background),
+ "appearance_changed",
+ background_appearance_changed_callback,
+ GTK_OBJECT (buffered_widget));
+ }
+ else {
+ /* g_print ("%s: No background found.\n", __FUNCTION__); */
+
+ /* FIXME: In this case, we should set a flag that indicates
+ * we need to check later for the precense of a background.
+ * Otherwise, we wont get background changes notifications,
+ * if the background gets attatched after we have been
+ * realized.
+ *
+ * Users of this code can easily work around this problem
+ * by attatching a background before the widget is realized,
+ * which is usually the case.
+ */
+ }
+}
+
+static void
+nautilus_buffered_widget_draw (GtkWidget *widget, GdkRectangle *area)
+{
+ NautilusBufferedWidget *buffered_widget;
+ GdkPoint source_point;
+ GdkRectangle destination_area;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (widget));
+ g_return_if_fail (area != NULL);
+ g_return_if_fail (GTK_WIDGET_REALIZED (widget));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (widget);
+
+ if (buffered_widget->detail->buffer_pixbuf == NULL) {
+ buffered_widget_update_pixbuf (buffered_widget);
+ }
+
+ source_point.x = 0;
+ source_point.y = 0;
+
+ destination_area.x = widget->allocation.x;
+ destination_area.y = widget->allocation.y;
+ destination_area.width = widget->allocation.width;
+ destination_area.height = widget->allocation.height;
+
+ nautilus_gdk_pixbuf_render_to_drawable (buffered_widget->detail->buffer_pixbuf,
+ widget->window,
+ buffered_widget->detail->copy_area_gc,
+ &source_point,
+ &destination_area,
+ GDK_INTERP_BILINEAR);
+}
+
+static void
+nautilus_buffered_widget_size_allocate (GtkWidget *widget, GtkAllocation* allocation)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (widget));
+ g_return_if_fail (allocation != NULL);
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (widget);
+
+ /* Assign the new allocation */
+ widget->allocation.x = allocation->x;
+ widget->allocation.y = allocation->y;
+ widget->allocation.width = MAX (1, allocation->width);
+ widget->allocation.height = MAX (1, allocation->height);
+
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->buffer_pixbuf);
+ buffered_widget->detail->buffer_pixbuf = NULL;
+}
+
+static gint
+nautilus_buffered_widget_expose (GtkWidget *widget, GdkEventExpose *event)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_val_if_fail (widget != NULL, FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (widget), FALSE);
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (widget);
+
+ nautilus_buffered_widget_draw (widget, &event->area);
+
+ return TRUE;
+}
+
+static GtkWidget *
+nautilus_gtk_widget_find_background_ancestor (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+ while (widget != NULL) {
+ if (nautilus_widget_has_attached_background (widget)) {
+ return widget;
+ }
+
+ widget = widget->parent;
+ }
+
+ return NULL;
+}
+
+static void
+nautilus_gdk_pixbuf_tile_alpha (GdkPixbuf *pixbuf,
+ const GdkPixbuf *tile_pixbuf,
+ guint tile_width,
+ guint tile_height,
+ gint tile_origin_x,
+ gint tile_origin_y,
+ GdkInterpType interpolation_mode,
+ guchar overall_alpha)
+{
+ gint x;
+ gint y;
+ guchar *pixels;
+ guchar *tile_pixels;
+ guint num_ver_iterations;
+ guint num_hor_iterations;
+ guint i;
+ guint j;
+ guint width;
+ guint height;
+
+ g_return_if_fail (pixbuf != NULL);
+ g_return_if_fail (tile_pixbuf != NULL);
+ g_return_if_fail (tile_width <= gdk_pixbuf_get_width (tile_pixbuf));
+ g_return_if_fail (tile_height <= gdk_pixbuf_get_height (tile_pixbuf));
+ g_return_if_fail (gdk_pixbuf_get_pixels (pixbuf) != NULL);
+ g_return_if_fail (gdk_pixbuf_get_pixels (tile_pixbuf) != NULL);
+
+ pixels = gdk_pixbuf_get_pixels (pixbuf);
+ tile_pixels = gdk_pixbuf_get_pixels (tile_pixbuf);
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+
+ num_ver_iterations = ceil (height / tile_height) + 1;
+ num_hor_iterations = ceil (width / tile_width) + 1;
+
+ y = 0;
+
+ for (j = 0; j < num_ver_iterations; j++)
+ {
+ x = 0;
+
+ for (i = 0; i < num_hor_iterations; i++)
+ {
+ guint copy_width;
+ guint copy_height;
+ gint dst_x;
+ gint dst_y;
+ gint dst_x2;
+ gint dst_y2;
+
+ dst_x = x;
+ dst_y = y;
+
+ copy_width = tile_width;
+ copy_height = tile_height;
+
+ dst_x2 = dst_x + copy_width;
+ dst_y2 = dst_y + copy_height;
+
+ if (dst_x2 > width)
+ {
+ copy_width -= (dst_x2 - width);
+ }
+
+ if (dst_y2 > height)
+ {
+ copy_height -= (dst_y2 - height);
+ }
+
+ if (copy_width > 0 && copy_height > 0)
+ {
+ GdkRectangle destination_area;
+
+ destination_area.x = dst_x;
+ destination_area.y = dst_y;
+ destination_area.width = copy_width;
+ destination_area.height = copy_height;
+
+ nautilus_gdk_pixbuf_render_to_pixbuf_alpha (tile_pixbuf,
+ pixbuf,
+ &destination_area,
+ interpolation_mode,
+ overall_alpha);
+ }
+
+ x += tile_width;
+ }
+
+ y += tile_height;
+ }
+}
+
+/* Private NautilusBufferedWidget things */
+static void
+buffered_widget_update_pixbuf (NautilusBufferedWidget *buffered_widget)
+{
+ GtkWidget *widget;
+ GdkPixbuf *pixbuf_without_alpha;
+ ArtIRect clip_rect;
+ GdkPoint destination_point;
+ NautilusBufferedWidgetClass *buffered_widget_class;
+
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget));
+
+ widget = GTK_WIDGET (buffered_widget);
+
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->buffer_pixbuf);
+
+ pixbuf_without_alpha = buffered_widget_create_pixbuf_from_background (buffered_widget,
+ buffered_widget->detail->copy_area_gc);
+ buffered_widget->detail->buffer_pixbuf = gdk_pixbuf_add_alpha (pixbuf_without_alpha, FALSE, 0, 0, 0);
+
+ gdk_pixbuf_unref (pixbuf_without_alpha);
+
+ g_assert (buffered_widget->detail->buffer_pixbuf != NULL);
+
+ clip_rect.x0 = 0;
+ clip_rect.y0 = 0;
+
+ clip_rect.x1 = widget->allocation.width;
+ clip_rect.y1 = widget->allocation.height;
+
+ destination_point.x = 0;
+ destination_point.y = 0;
+
+ buffered_widget_class = NAUTILUS_BUFFERED_WIDGET_CLASS (NAUTILUS_CLASS (buffered_widget));
+ g_assert (buffered_widget_class != NULL);
+ g_assert (buffered_widget_class->render_buffer_pixbuf != NULL);
+
+ if (buffered_widget->detail->tile_pixbuf != NULL) {
+ nautilus_gdk_pixbuf_tile_alpha (buffered_widget->detail->buffer_pixbuf,
+ buffered_widget->detail->tile_pixbuf,
+ gdk_pixbuf_get_width (buffered_widget->detail->tile_pixbuf),
+ gdk_pixbuf_get_height (buffered_widget->detail->tile_pixbuf),
+ 0,
+ 0,
+ GDK_INTERP_BILINEAR,
+ 255); /* image->detail->overall_alpha */
+ }
+
+ NAUTILUS_CALL_VIRTUAL (NAUTILUS_BUFFERED_WIDGET_CLASS, buffered_widget, render_buffer_pixbuf,
+ (buffered_widget, buffered_widget->detail->buffer_pixbuf));
+}
+
+static GdkPixbuf*
+buffered_widget_create_pixbuf_from_background (const NautilusBufferedWidget *buffered_widget,
+ GdkGC *gc)
+{
+ GtkWidget *widget;
+ GdkPixbuf *pixbuf;
+ GtkWidget *background_ancestor;
+
+ g_return_val_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget), NULL);
+ g_return_val_if_fail (gc != NULL, NULL);
+
+ widget = GTK_WIDGET (buffered_widget);
+
+ background_ancestor = nautilus_gtk_widget_find_background_ancestor (widget);
+
+ if (background_ancestor != NULL) {
+ NautilusBackground *background;
+ GdkPixmap *pixmap;
+ GdkRectangle background_area;
+
+ background = nautilus_get_widget_background (background_ancestor);
+ g_assert (NAUTILUS_IS_BACKGROUND (background));
+
+ background_area.x = 0;
+ background_area.y = 0;
+ background_area.width = background_ancestor->allocation.width;
+ background_area.height = background_ancestor->allocation.height;
+
+ pixmap = gdk_pixmap_new (widget->window, background_area.width, background_area.height, -1);
+
+ nautilus_background_draw (background, pixmap, gc, &background_area, 0, 0);
+
+ pixbuf = gdk_pixbuf_get_from_drawable (NULL,
+ pixmap,
+ gdk_rgb_get_cmap (),
+ widget->allocation.x,
+ widget->allocation.y,
+ 0,
+ 0,
+ widget->allocation.width,
+ widget->allocation.height);
+
+ gdk_pixmap_unref (pixmap);
+ }
+ else {
+ GdkPixmap *pixmap;
+
+ pixmap = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1);
+
+ gtk_paint_box (widget->style,
+ pixmap,
+ GTK_STATE_NORMAL,
+ GTK_SHADOW_NONE,
+ NULL,
+ widget,
+ "entry_bg",
+ 0,
+ 0,
+ widget->allocation.width,
+ widget->allocation.height);
+
+ pixbuf = gdk_pixbuf_get_from_drawable (NULL,
+ pixmap,
+ gdk_rgb_get_cmap (),
+ 0,
+ 0,
+ 0,
+ 0,
+ widget->allocation.width,
+ widget->allocation.height);
+ }
+
+ g_assert (pixbuf != NULL);
+
+ return pixbuf;
+}
+
+static void
+background_appearance_changed_callback (NautilusBackground *background,
+ gpointer callback_data)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (callback_data));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (callback_data);
+
+ nautilus_buffered_widget_clear_buffer (buffered_widget);
+
+ gtk_widget_queue_draw (GTK_WIDGET (buffered_widget));
+}
+
+/**
+ * nautilus_buffered_widget_clear_buffer:
+ *
+ * @buffered_widget: A NautilusBufferedWidget
+ *
+ * Clear the internal buffer so that the next time the widget is drawn,
+ * the buffer will be re-composited. This is useful when you've manually
+ * done something to the widget that changes it appearance. This is mostly
+ * useful for subclasses.
+ */
+void
+nautilus_buffered_widget_clear_buffer (NautilusBufferedWidget *buffered_widget)
+{
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget));
+
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->buffer_pixbuf);
+ buffered_widget->detail->buffer_pixbuf = NULL;
+}
+
+/**
+ * nautilus_buffered_widget_set_tile_pixbuf:
+ *
+ * @buffered_widget: A NautilusBufferedWidget
+ * @pixbuf: The new tile pixbuf
+ *
+ * Change the tile pixbuf. A 'pixbuf' value of NULL, means dont use a
+ * tile pixbuf - this is the default behavior for the widget.
+ */
+void
+nautilus_buffered_widget_set_tile_pixbuf (NautilusBufferedWidget *buffered_widget,
+ GdkPixbuf *pixbuf)
+{
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget));
+
+ if (pixbuf != buffered_widget->detail->tile_pixbuf)
+ {
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->tile_pixbuf);
+
+ nautilus_gdk_pixbuf_ref_if_not_null (pixbuf);
+
+ buffered_widget->detail->tile_pixbuf = pixbuf;
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (buffered_widget));
+}
+
+/**
+ * nautilus_buffered_widget_get_tile_pixbuf:
+ *
+ * @buffered_widget: A NautilusBufferedWidget
+ *
+ * Return value: A reference to the tile_pixbuf. Needs to be unreferenced with
+ * gdk_pixbuf_unref()
+ */
+GdkPixbuf*
+nautilus_buffered_widget_get_tile_pixbuf (const NautilusBufferedWidget *buffered_widget)
+{
+ g_return_val_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget), NULL);
+
+ nautilus_gdk_pixbuf_ref_if_not_null (buffered_widget->detail->tile_pixbuf);
+
+ return buffered_widget->detail->tile_pixbuf;
+}
diff --git a/libnautilus-extensions/nautilus-buffered-widget.h b/libnautilus-extensions/nautilus-buffered-widget.h
new file mode 100644
index 000000000..c7900badb
--- /dev/null
+++ b/libnautilus-extensions/nautilus-buffered-widget.h
@@ -0,0 +1,87 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-buffered-widget.h - A buffered widget for alpha compositing.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+/* NautilusBufferedWidget is a virtual widget class that encapsulates the
+ * details of finding a suitable background for compositing pixbufs.
+
+ * The background can be installed as NautilusBackground on a NautilusImage
+ * widget or any of its ancestors.
+ *
+ * The background can also be that provided by the GtkStyle attatched to the
+ * widget.
+ *
+ * The best background will automatically be found and used by the widget.
+ *
+ * Also, a tile_pixbuf can be installed to create tiling effects on top of
+ * the default background.
+ */
+
+#ifndef NAUTILUS_BUFFERED_WIDGET_H
+#define NAUTILUS_BUFFERED_WIDGET_H
+
+#include <gtk/gtkmisc.h>
+#include <libgnome/gnome-defs.h>
+
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+BEGIN_GNOME_DECLS
+
+#define NAUTILUS_TYPE_BUFFERED_WIDGET (nautilus_buffered_widget_get_type ())
+#define NAUTILUS_BUFFERED_WIDGET(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_BUFFERED_WIDGET, NautilusBufferedWidget))
+#define NAUTILUS_BUFFERED_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_BUFFERED_WIDGET, NautilusBufferedWidgetClass))
+#define NAUTILUS_IS_BUFFERED_WIDGET(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_BUFFERED_WIDGET))
+#define NAUTILUS_IS_BUFFERED_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BUFFERED_WIDGET))
+
+typedef struct _NautilusBufferedWidget NautilusBufferedWidget;
+typedef struct _NautilusBufferedWidgetClass NautilusBufferedWidgetClass;
+typedef struct _NautilusBufferedWidgetDetail NautilusBufferedWidgetDetail;
+
+struct _NautilusBufferedWidget
+{
+ /* Superclass */
+ GtkMisc misc;
+
+ /* Private things */
+ NautilusBufferedWidgetDetail *detail;
+};
+
+struct _NautilusBufferedWidgetClass
+{
+ GtkMiscClass parent_class;
+
+ void (*render_buffer_pixbuf) (NautilusBufferedWidget *buffered_widget, GdkPixbuf *buffer);
+};
+
+GtkType nautilus_buffered_widget_get_type (void);
+void nautilus_buffered_widget_clear_buffer (NautilusBufferedWidget *buffered_widget);
+void nautilus_buffered_widget_set_tile_pixbuf (NautilusBufferedWidget *image,
+ GdkPixbuf *pixbuf);
+GdkPixbuf* nautilus_buffered_widget_get_tile_pixbuf (const NautilusBufferedWidget *image);
+
+END_GNOME_DECLS
+
+#endif /* NAUTILUS_BUFFERED_WIDGET_H */
+
+
diff --git a/libnautilus-extensions/nautilus-font-picker.c b/libnautilus-extensions/nautilus-font-picker.c
new file mode 100644
index 000000000..f68bd1ee1
--- /dev/null
+++ b/libnautilus-extensions/nautilus-font-picker.c
@@ -0,0 +1,497 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-font-picker.c - A simple widget to select scalable fonts.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+
+#include "nautilus-font-picker.h"
+#include "nautilus-gtk-macros.h"
+#include "nautilus-glib-extensions.h"
+#include "nautilus-string-picker.h"
+#include "nautilus-string.h"
+
+#include <gtk/gtklabel.h>
+#include <gtk/gtkentry.h>
+
+static const gint FONT_PICKER_SPACING = 10;
+
+/* Signals */
+typedef enum
+{
+ SELECTED_FONT_CHANGED,
+ LAST_SIGNAL
+} FontPickerSignals;
+
+struct _NautilusFontPickerDetail
+{
+ GtkWidget *family_picker;
+ GtkWidget *weight_picker;
+ GtkWidget *slant_picker;
+ GtkWidget *set_width_picker;
+
+ NautilusStringList *weight_list;
+ NautilusStringList *slant_list;
+ NautilusStringList *set_width_list;
+};
+
+/* NautilusFontPickerClass methods */
+static void nautilus_font_picker_initialize_class (NautilusFontPickerClass *klass);
+static void nautilus_font_picker_initialize (NautilusFontPicker *font_picker);
+
+
+/* GtkObjectClass methods */
+static void nautilus_font_picker_destroy (GtkObject *object);
+static void family_picker_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+static void weight_picker_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+static void slant_picker_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+static void set_width_picker_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontPicker, nautilus_font_picker, GTK_TYPE_HBOX)
+
+static guint font_picker_signals[LAST_SIGNAL] = { 0 };
+
+/*
+ * NautilusFontPickerClass methods
+ */
+static void
+nautilus_font_picker_initialize_class (NautilusFontPickerClass *font_picker_class)
+{
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = GTK_OBJECT_CLASS (font_picker_class);
+ widget_class = GTK_WIDGET_CLASS (font_picker_class);
+
+ /* GtkObjectClass */
+ object_class->destroy = nautilus_font_picker_destroy;
+
+ /* Signals */
+ font_picker_signals[SELECTED_FONT_CHANGED] = gtk_signal_new ("selected_font_changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ 0,
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE,
+ 0);
+
+ gtk_object_class_add_signals (object_class, font_picker_signals, LAST_SIGNAL);
+}
+
+static void
+nautilus_font_picker_initialize (NautilusFontPicker *font_picker)
+{
+ NautilusStringList *family_list;
+
+ font_picker->detail = g_new (NautilusFontPickerDetail, 1);
+
+ font_picker->detail->weight_list = NULL;
+ font_picker->detail->slant_list = NULL;
+ font_picker->detail->set_width_list = NULL;
+
+ gtk_box_set_homogeneous (GTK_BOX (font_picker), FALSE);
+ gtk_box_set_spacing (GTK_BOX (font_picker), FONT_PICKER_SPACING);
+
+ font_picker->detail->family_picker = nautilus_string_picker_new ();
+ font_picker->detail->weight_picker = nautilus_string_picker_new ();
+ font_picker->detail->slant_picker = nautilus_string_picker_new ();
+ font_picker->detail->set_width_picker = nautilus_string_picker_new ();
+
+ gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->family_picker, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->weight_picker, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->slant_picker, TRUE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (font_picker), font_picker->detail->set_width_picker, TRUE, TRUE, 0);
+
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_picker->detail->family_picker), _("Font"));
+
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->family_picker), FALSE);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->weight_picker), FALSE);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->slant_picker), FALSE);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->set_width_picker), FALSE);
+
+ family_list = nautilus_scalable_font_get_font_family_list ();
+
+ nautilus_string_list_sort (family_list);
+
+ /* FIXME: Need to deal with possiblity of there being no fonts */
+ g_assert (family_list != NULL);
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker),
+ family_list);
+
+ nautilus_string_list_free (family_list);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker->detail->family_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (family_picker_changed_callback),
+ font_picker);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker->detail->weight_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (weight_picker_changed_callback),
+ font_picker);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker->detail->slant_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (slant_picker_changed_callback),
+ font_picker);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker->detail->set_width_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (set_width_picker_changed_callback),
+ font_picker);
+
+ gtk_widget_show (font_picker->detail->family_picker);
+ gtk_widget_show (font_picker->detail->weight_picker);
+ gtk_widget_show (font_picker->detail->slant_picker);
+ gtk_widget_show (font_picker->detail->set_width_picker);
+
+ family_picker_changed_callback (font_picker->detail->family_picker, font_picker);
+}
+
+/* GtkObjectClass methods */
+static void
+nautilus_font_picker_destroy (GtkObject* object)
+{
+ NautilusFontPicker * font_picker;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (object));
+
+ font_picker = NAUTILUS_FONT_PICKER (object);
+
+ nautilus_string_list_free (font_picker->detail->weight_list);
+ nautilus_string_list_free (font_picker->detail->slant_list);
+ nautilus_string_list_free (font_picker->detail->set_width_list);
+
+ g_free (font_picker->detail);
+
+ /* Chain */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static void
+font_picker_update_weight_picker (NautilusFontPicker *font_picker)
+{
+ NautilusStringList *unique_weight_list;
+ char *family;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
+
+ unique_weight_list = nautilus_string_list_new_from_string_list (font_picker->detail->weight_list);
+
+ nautilus_string_list_sort (unique_weight_list);
+ nautilus_string_list_remove_duplicates (unique_weight_list);
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker),
+ unique_weight_list);
+
+ nautilus_string_list_free (unique_weight_list);
+
+ g_free (family);
+}
+
+static void
+font_picker_update_slant_picker (NautilusFontPicker *font_picker)
+{
+ NautilusStringList *unique_slant_list;
+ char *current_family;
+ char *current_weight;
+ guint i;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ current_family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
+ current_weight = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
+
+ g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
+ nautilus_string_list_get_length (font_picker->detail->weight_list));
+
+ unique_slant_list = nautilus_string_list_new ();
+
+ for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->slant_list); i++) {
+ char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
+ char *slant = nautilus_string_list_nth (font_picker->detail->slant_list, i);
+
+ if (nautilus_str_is_equal (current_weight, weight)) {
+ nautilus_string_list_insert (unique_slant_list, slant);
+ }
+
+ g_free (weight);
+ g_free (slant);
+ }
+
+ nautilus_string_list_sort (unique_slant_list);
+ nautilus_string_list_remove_duplicates (unique_slant_list);
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker),
+ unique_slant_list);
+
+ nautilus_string_list_free (unique_slant_list);
+
+ g_free (current_family);
+ g_free (current_weight);
+}
+
+static void
+font_picker_update_set_width_picker (NautilusFontPicker *font_picker)
+{
+ NautilusStringList *unique_set_width_list;
+ char *current_family;
+ char *current_weight;
+ char *current_slant;
+ guint i;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ current_family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
+ current_weight = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
+ current_slant = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker));
+
+ g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
+ nautilus_string_list_get_length (font_picker->detail->weight_list));
+
+ g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
+ nautilus_string_list_get_length (font_picker->detail->set_width_list));
+
+ unique_set_width_list = nautilus_string_list_new ();
+
+ for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->set_width_list); i++) {
+ char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
+ char *slant = nautilus_string_list_nth (font_picker->detail->slant_list, i);
+ char *set_width = nautilus_string_list_nth (font_picker->detail->set_width_list, i);
+
+ if (nautilus_str_is_equal (current_weight, weight)
+ && nautilus_str_is_equal (current_slant, slant)) {
+ nautilus_string_list_insert (unique_set_width_list, set_width);
+ }
+
+ g_free (weight);
+ g_free (slant);
+ g_free (set_width);
+ }
+
+ nautilus_string_list_sort (unique_set_width_list);
+ nautilus_string_list_remove_duplicates (unique_set_width_list);
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker),
+ unique_set_width_list);
+
+ nautilus_string_list_free (unique_set_width_list);
+
+ g_free (current_family);
+ g_free (current_weight);
+ g_free (current_slant);
+}
+
+static void
+family_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+{
+ NautilusFontPicker *font_picker;
+ char *family;
+ NautilusStringList *weight_list = NULL;
+ NautilusStringList *slant_list = NULL;
+ NautilusStringList *set_width_list = NULL;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ font_picker = NAUTILUS_FONT_PICKER (user_data);
+
+ family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (string_picker));
+
+ if (nautilus_scalable_font_query_font (family, &weight_list, &slant_list, &set_width_list)) {
+ nautilus_string_list_free (font_picker->detail->weight_list);
+ nautilus_string_list_free (font_picker->detail->slant_list);
+ nautilus_string_list_free (font_picker->detail->set_width_list);
+
+ font_picker->detail->weight_list = weight_list;
+ font_picker->detail->slant_list = slant_list;
+ font_picker->detail->set_width_list = set_width_list;
+
+ font_picker_update_weight_picker (font_picker);
+ font_picker_update_slant_picker (font_picker);
+ font_picker_update_set_width_picker (font_picker);
+
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+ }
+ else {
+ g_warning ("Trying to set a bogus non existant font '%s'\n", family);
+ }
+
+ g_free (family);
+}
+
+static void
+weight_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+{
+ NautilusFontPicker *font_picker;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ font_picker = NAUTILUS_FONT_PICKER (user_data);
+
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+}
+
+static void
+slant_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+{
+ NautilusFontPicker *font_picker;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ font_picker = NAUTILUS_FONT_PICKER (user_data);
+
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+}
+
+static void
+set_width_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+{
+ NautilusFontPicker *font_picker;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ font_picker = NAUTILUS_FONT_PICKER (user_data);
+
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+}
+
+
+/*
+ * NautilusFontPicker public methods
+ */
+GtkWidget*
+nautilus_font_picker_new (void)
+{
+ NautilusFontPicker *font_picker;
+
+ font_picker = gtk_type_new (nautilus_font_picker_get_type ());
+
+ return GTK_WIDGET (font_picker);
+}
+
+void
+nautilus_font_picker_set_selected_family (NautilusFontPicker *font_picker,
+ const char *family)
+{
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (family != NULL);
+
+ if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker), family)) {
+ g_warning ("Trying to set a bogus family '%s'\n", family);
+ return;
+ }
+
+ nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker),
+ family);
+}
+
+void
+nautilus_font_picker_set_selected_weight (NautilusFontPicker *font_picker,
+ const char *weight)
+{
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (weight != NULL);
+
+ if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker), weight)) {
+ g_warning ("Trying to set a bogus weight '%s'\n", weight);
+ return;
+ }
+
+ nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker),
+ weight);
+}
+
+void
+nautilus_font_picker_set_selected_slant (NautilusFontPicker *font_picker,
+ const char *slant)
+{
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (slant != NULL);
+
+ if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker), slant)) {
+ g_warning ("Trying to set a bogus slant '%s'\n", slant);
+ return;
+ }
+
+ nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker),
+ slant);
+}
+
+void
+nautilus_font_picker_set_selected_set_width (NautilusFontPicker *font_picker,
+ const char *set_width)
+{
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (set_width != NULL);
+
+ if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker), set_width)) {
+ g_warning ("Trying to set a bogus set_width '%s'\n", set_width);
+ return;
+ }
+
+ nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker),
+ set_width);
+}
+
+char *
+nautilus_font_picker_get_selected_family (const NautilusFontPicker *font_picker)
+{
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
+}
+
+char *
+nautilus_font_picker_get_selected_weight (const NautilusFontPicker *font_picker)
+{
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
+}
+
+char *
+nautilus_font_picker_get_selected_slant (const NautilusFontPicker *font_picker)
+{
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker));
+}
+
+char *
+nautilus_font_picker_get_selected_set_width (const NautilusFontPicker *font_picker)
+{
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker));
+}
diff --git a/libnautilus-extensions/nautilus-font-picker.h b/libnautilus-extensions/nautilus-font-picker.h
new file mode 100644
index 000000000..381267d43
--- /dev/null
+++ b/libnautilus-extensions/nautilus-font-picker.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-font-picker.h - A simple widget to select scalable fonts.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#ifndef NAUTILUS_FONT_PICKER_H
+#define NAUTILUS_FONT_PICKER_H
+
+#include <gtk/gtkvbox.h>
+#include <gnome.h>
+
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+
+BEGIN_GNOME_DECLS
+
+#define NAUTILUS_TYPE_FONT_PICKER (nautilus_font_picker_get_type ())
+#define NAUTILUS_FONT_PICKER(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_FONT_PICKER, NautilusFontPicker))
+#define NAUTILUS_FONT_PICKER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_FONT_PICKER, NautilusFontPickerClass))
+#define NAUTILUS_IS_FONT_PICKER(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_FONT_PICKER))
+
+typedef struct _NautilusFontPicker NautilusFontPicker;
+typedef struct _NautilusFontPickerClass NautilusFontPickerClass;
+typedef struct _NautilusFontPickerDetail NautilusFontPickerDetail;
+
+struct _NautilusFontPicker
+{
+ /* Super Class */
+ GtkHBox hbox;
+
+ /* Private stuff */
+ NautilusFontPickerDetail *detail;
+};
+
+struct _NautilusFontPickerClass
+{
+ GtkHBoxClass parent_class;
+};
+
+GtkType nautilus_font_picker_get_type (void);
+GtkWidget* nautilus_font_picker_new (void);
+void nautilus_font_picker_set_show_weights (NautilusFontPicker *font_picker);
+void nautilus_font_picker_set_show_slants (NautilusFontPicker *font_picker);
+void nautilus_font_picker_set_show_set_widths (NautilusFontPicker *font_picker);
+void nautilus_font_picker_set_selected_family (NautilusFontPicker *font_picker,
+ const char *family);
+void nautilus_font_picker_set_selected_weight (NautilusFontPicker *font_picker,
+ const char *weight);
+void nautilus_font_picker_set_selected_slant (NautilusFontPicker *font_picker,
+ const char *slant);
+void nautilus_font_picker_set_selected_set_width (NautilusFontPicker *font_picker,
+ const char *set_width);
+char * nautilus_font_picker_get_selected_family (const NautilusFontPicker *font_picker);
+char * nautilus_font_picker_get_selected_weight (const NautilusFontPicker *font_picker);
+char * nautilus_font_picker_get_selected_slant (const NautilusFontPicker *font_picker);
+char * nautilus_font_picker_get_selected_set_width (const NautilusFontPicker *font_picker);
+
+BEGIN_GNOME_DECLS
+
+#endif /* NAUTILUS_FONT_PICKER_H */
+
+
diff --git a/libnautilus-extensions/nautilus-image.c b/libnautilus-extensions/nautilus-image.c
index e8f829533..402ad70eb 100644
--- a/libnautilus-extensions/nautilus-image.c
+++ b/libnautilus-extensions/nautilus-image.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* nautilus-image.c - A widget to display a composited pixbuf.
+/* nautilus-image.c - A widget to display a alpha composited pixbufs.
Copyright (C) 1999, 2000 Eazel, Inc.
@@ -25,25 +25,16 @@
#include <config.h>
#include "nautilus-image.h"
+#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-gdk-extensions.h"
#include "nautilus-gdk-pixbuf-extensions.h"
-#include <math.h>
-#include <string.h>
-
-/* FIXME bugzilla.eazel.com 1612:
- * We should use NautilusBackground for the background. This will simplify
- * lots of things, be more efficient, and remove the need for a lot of the
- * tiling code.
- */
-
/* Arguments */
enum
{
ARG_0,
ARG_BACKGROUND_COLOR,
- ARG_BACKGROUND_PIXBUF,
ARG_BACKGROUND_TYPE,
ARG_IMAGE,
ARG_PLACEMENT_TYPE,
@@ -52,163 +43,42 @@ enum
/* Detail member struct */
struct _NautilusImageDetail
{
- /* Attributes */
- NautilusImagePlacementType placement_type;
- NautilusImageBackgroundType background_type;
- GdkPixbuf *background_pixbuf;
- guint32 background_color;
- GdkPixbuf *pixbuf;
- GdkPoint background_tile_origin;
- guchar overall_alpha;
- gboolean background_tile_screen_relative;
-
- gchar *label_text;
- GdkFont *label_font;
-
- GdkGC *copy_area_gc;
- GdkPixbuf *buffer;
-
- /* Offsets */
- guint left_offset;
- guint right_offset;
- guint top_offset;
- guint bottom_offset;
-
- guint extra_width;
- guint extra_height;
+ GdkPixbuf *pixbuf;
+ guchar overall_alpha;
};
/* GtkObjectClass methods */
-static void nautilus_image_initialize_class (NautilusImageClass *image_class);
-static void nautilus_image_initialize (NautilusImage *image);
-static void nautilus_image_destroy (GtkObject *object);
-static void nautilus_image_set_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id);
-static void nautilus_image_get_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id);
+static void nautilus_image_initialize_class (NautilusImageClass *image_class);
+static void nautilus_image_initialize (NautilusImage *image);
+static void nautilus_image_destroy (GtkObject *object);
+static void nautilus_image_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+static void nautilus_image_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+/* GtkWidgetClass methods */
+static void nautilus_image_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
-/* GtkWidgetClass methods */
-static void nautilus_image_map (GtkWidget *widget);
-static void nautilus_image_unmap (GtkWidget *widget);
-static void nautilus_image_realize (GtkWidget *widget);
-static void nautilus_image_unrealize (GtkWidget *widget);
-static void nautilus_image_draw (GtkWidget *widget,
- GdkRectangle *area);
-static void nautilus_image_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void nautilus_image_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-
-
-/* GtkWidgetClass event methods */
-static gint nautilus_image_expose (GtkWidget *widget,
- GdkEventExpose *event);
+/* NautilusBufferedWidgetClass methods */
+static void render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
+ GdkPixbuf *buffer);
-/* Private NautilusImage things */
-static void ensure_buffer_size (NautilusImage *image,
- guint width,
- guint height);
-static GdkGC * nautilus_gdk_create_copy_area_gc (GdkWindow *window);
-static void nautilus_gdk_pixbuf_render_to_drawable (const GdkPixbuf *pixbuf,
- GdkDrawable *drawable,
- GdkGC *gc,
- const GdkPoint *source_point,
- const GdkRectangle *destination_area,
- GdkRgbDither dither);
-static void nautilus_gdk_pixbuf_render_to_pixbuf (const GdkPixbuf *pixbuf,
- GdkPixbuf *destination_pixbuf,
- const GdkPoint *source_point,
- const GdkRectangle *destination_area);
-static void nautilus_gdk_pixbuf_render_to_pixbuf_alpha (const GdkPixbuf *pixbuf,
- GdkPixbuf *destination_pixbuf,
- const GdkRectangle *destination_area,
- GdkInterpType interpolation_mode,
- guchar overall_alpha);
-static void gdk_string_dimensions (const GdkFont *font,
- const gchar *string,
- GtkRequisition *size);
-static void nautilus_gdk_pixbuf_set_to_color (GdkPixbuf *pixbuf,
- guint32 color);
-static void nautilus_gdk_pixbuf_tile (GdkPixbuf *pixbuf,
- const GdkPixbuf *tile_pixbuf,
- guint tile_width,
- guint tile_height,
- gint tile_origin_x,
- gint tile_origin_y);
-static void nautilus_gdk_pixbuf_tile_alpha (GdkPixbuf *pixbuf,
- const GdkPixbuf *tile_pixbuf,
- guint tile_width,
- guint tile_height,
- gint tile_origin_x,
- gint tile_origin_y,
- GdkInterpType interpolation_mode,
- guchar overall_alpha);
-#define NAUTILUS_ALPHA_NONE 255
-
-#define NAUTILUS_MACRO_BEGIN G_STMT_START {
-#define NAUTILUS_MACRO_END } G_STMT_END
-
-/* GdkPixbuf refcounting macros */
-#define NAUTILUS_GDK_PIXBUF_UNREF_IF(_pixbuf) \
-NAUTILUS_MACRO_BEGIN \
- if ((_pixbuf) != NULL) { \
- gdk_pixbuf_unref (_pixbuf); \
- (_pixbuf) = NULL; \
- } \
-NAUTILUS_MACRO_END
-
-#define NAUTILUS_GDK_PIXBUF_REF_IF(_pixbuf) \
-NAUTILUS_MACRO_BEGIN \
- if ((_pixbuf) != NULL) { \
- gdk_pixbuf_ref (_pixbuf); \
- } \
-NAUTILUS_MACRO_END
-
-/* GdkGC refcounting macros */ \
-#define NAUTILUS_GDK_GC_UNREF_IF(_gc) \
-NAUTILUS_MACRO_BEGIN \
- if ((_gc) != NULL) { \
- gdk_gc_unref (_gc); \
- (_gc) = NULL; \
- } \
-NAUTILUS_MACRO_END
-
-#define NAUTILUS_GDK_GC_REF_IF(_gc) \
-NAUTILUS_MACRO_BEGIN \
- if ((_gc) != NULL) { \
- gdk_gc_ref (_gc); \
- } \
-NAUTILUS_MACRO_END
-
-/* GdkFont refcounting macros */
-#define NAUTILUS_GDK_FONT_UNREF_IF(_font) \
-NAUTILUS_MACRO_BEGIN \
- if ((_font) != NULL) { \
- gdk_font_unref (_font); \
- (_font) = NULL; \
- } \
-NAUTILUS_MACRO_END
-
-#define NAUTILUS_GDK_FONT_REF_IF(_font) \
-NAUTILUS_MACRO_BEGIN \
- if ((_font) != NULL) { \
- gdk_font_ref (_font); \
- } \
-NAUTILUS_MACRO_END
-
-NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusImage, nautilus_image, GTK_TYPE_MISC)
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusImage, nautilus_image, NAUTILUS_TYPE_BUFFERED_WIDGET)
/* Class init methods */
static void
nautilus_image_initialize_class (NautilusImageClass *image_class)
{
- GtkObjectClass *object_class = GTK_OBJECT_CLASS (image_class);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (image_class);
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (image_class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (image_class);
+ NautilusBufferedWidgetClass *buffered_widget_class = NAUTILUS_BUFFERED_WIDGET_CLASS (image_class);
+#if 0
/* Arguments */
gtk_object_add_arg_type ("NautilusImage::placement_type",
GTK_TYPE_ENUM,
@@ -220,11 +90,6 @@ nautilus_image_initialize_class (NautilusImageClass *image_class)
GTK_ARG_READWRITE,
ARG_BACKGROUND_TYPE);
- gtk_object_add_arg_type ("NautilusImage::background_pixbuf",
- GTK_TYPE_OBJECT,
- GTK_ARG_READWRITE,
- ARG_BACKGROUND_PIXBUF);
-
gtk_object_add_arg_type ("NautilusImage::background_color",
GTK_TYPE_UINT,
GTK_ARG_READWRITE,
@@ -234,6 +99,7 @@ nautilus_image_initialize_class (NautilusImageClass *image_class)
GTK_TYPE_OBJECT,
GTK_ARG_READWRITE,
ARG_IMAGE);
+#endif
/* GtkObjectClass */
object_class->destroy = nautilus_image_destroy;
@@ -241,49 +107,19 @@ nautilus_image_initialize_class (NautilusImageClass *image_class)
object_class->get_arg = nautilus_image_get_arg;
/* GtkWidgetClass */
- widget_class->realize = nautilus_image_realize;
- widget_class->unrealize = nautilus_image_unrealize;
- widget_class->draw = nautilus_image_draw;
- widget_class->map = nautilus_image_map;
- widget_class->unmap = nautilus_image_unmap;
- widget_class->expose_event = nautilus_image_expose;
widget_class->size_request = nautilus_image_size_request;
- widget_class->size_allocate = nautilus_image_size_allocate;
+
+ /* NautilusBufferedWidgetClass */
+ buffered_widget_class->render_buffer_pixbuf = render_buffer_pixbuf;
}
void
nautilus_image_initialize (NautilusImage *image)
{
- GTK_WIDGET_SET_FLAGS (image, GTK_CAN_FOCUS);
- GTK_WIDGET_UNSET_FLAGS (image, GTK_NO_WINDOW);
-
image->detail = g_new (NautilusImageDetail, 1);
- image->detail->placement_type = NAUTILUS_IMAGE_PLACEMENT_CENTER;
-
- image->detail->background_color = NAUTILUS_RGB_COLOR_WHITE;
- image->detail->background_type = NAUTILUS_IMAGE_BACKGROUND_SOLID;
- image->detail->background_pixbuf = NULL;
-
image->detail->pixbuf = NULL;
-
- image->detail->buffer = NULL;
- image->detail->copy_area_gc = NULL;
- image->detail->label_text = NULL;
- image->detail->label_font = gdk_font_load ("fixed");
-
- image->detail->background_tile_origin.x = 0;
- image->detail->background_tile_origin.y = 0;
- image->detail->overall_alpha = NAUTILUS_ALPHA_NONE;
- image->detail->background_tile_screen_relative = TRUE;
-
- image->detail->left_offset = 0;
- image->detail->right_offset = 0;
- image->detail->top_offset = 0;
- image->detail->bottom_offset = 0;
-
- image->detail->extra_width = 0;
- image->detail->extra_height = 0;
+ image->detail->overall_alpha = 255;
}
/* GtkObjectClass methods */
@@ -297,14 +133,8 @@ nautilus_image_destroy (GtkObject *object)
image = NAUTILUS_IMAGE (object);
- NAUTILUS_GDK_GC_UNREF_IF (image->detail->copy_area_gc);
- NAUTILUS_GDK_FONT_UNREF_IF (image->detail->label_font);
-
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->buffer);
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->background_pixbuf);
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->pixbuf);
-
- g_free (image->detail->label_text);
+ nautilus_gdk_pixbuf_unref_if_not_null (image->detail->pixbuf);
+ image->detail->pixbuf = NULL;
g_free (image->detail);
@@ -314,8 +144,8 @@ nautilus_image_destroy (GtkObject *object)
static void
nautilus_image_set_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id)
+ GtkArg *arg,
+ guint arg_id)
{
NautilusImage *image;
@@ -324,6 +154,7 @@ nautilus_image_set_arg (GtkObject *object,
image = NAUTILUS_IMAGE (object);
+#if 0
switch (arg_id)
{
case ARG_PLACEMENT_TYPE:
@@ -334,10 +165,6 @@ nautilus_image_set_arg (GtkObject *object,
image->detail->background_type = GTK_VALUE_ENUM (*arg);
break;
- case ARG_BACKGROUND_PIXBUF:
- nautilus_image_set_background_pixbuf (image, (GdkPixbuf*) GTK_VALUE_OBJECT (*arg));
- break;
-
case ARG_BACKGROUND_COLOR:
image->detail->background_color = GTK_VALUE_UINT (*arg);
break;
@@ -349,6 +176,7 @@ nautilus_image_set_arg (GtkObject *object,
default:
g_assert_not_reached ();
}
+#endif
}
static void
@@ -363,6 +191,7 @@ nautilus_image_get_arg (GtkObject *object,
image = NAUTILUS_IMAGE (object);
+#if 0
switch (arg_id)
{
case ARG_PLACEMENT_TYPE:
@@ -373,10 +202,6 @@ nautilus_image_get_arg (GtkObject *object,
GTK_VALUE_ENUM (*arg) = image->detail->background_type;
break;
- case ARG_BACKGROUND_PIXBUF:
- GTK_VALUE_OBJECT (*arg) = (GtkObject *) nautilus_image_get_background_pixbuf (image);
- break;
-
case ARG_BACKGROUND_COLOR:
GTK_VALUE_UINT (*arg) = image->detail->background_color;
break;
@@ -388,818 +213,79 @@ nautilus_image_get_arg (GtkObject *object,
default:
g_assert_not_reached ();
}
+#endif
}
/* GtkWidgetClass methods */
-static void
-nautilus_image_realize (GtkWidget *widget)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
-
- image = NAUTILUS_IMAGE (widget);
-
- /* Chain realize */
- NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, realize, (widget));
-
- /* Create GCs */
- image->detail->copy_area_gc = nautilus_gdk_create_copy_area_gc (widget->window);
-}
-
-static void
-nautilus_image_unrealize (GtkWidget *widget)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
-
- image = NAUTILUS_IMAGE (widget);
-
- NAUTILUS_GDK_GC_UNREF_IF (image->detail->copy_area_gc);
-
- /* Chain unrealize */
- NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, unrealize, (widget));
-}
static void
-nautilus_image_draw (GtkWidget *widget, GdkRectangle *area)
+nautilus_image_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
{
NautilusImage *image;
- GdkPoint source_point;
- GdkRectangle destination_area;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
- g_return_if_fail (area != NULL);
-
- image = NAUTILUS_IMAGE (widget);
-
- source_point.x = area->x;
- source_point.y = area->y;
-
- destination_area.x = area->x;
- destination_area.y = area->y;
- destination_area.width = widget->allocation.width - area->x;
- destination_area.height = widget->allocation.height - area->y;
-
- nautilus_gdk_pixbuf_render_to_drawable (image->detail->buffer,
- widget->window,
- image->detail->copy_area_gc,
- &source_point,
- &destination_area,
- GDK_INTERP_NEAREST);
-}
-
-static void
-nautilus_image_size_allocate (GtkWidget *widget, GtkAllocation* allocation)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
- g_return_if_fail (allocation != NULL);
-
- image = NAUTILUS_IMAGE (widget);
-
- /* Assign the new allocation */
- widget->allocation.x = allocation->x;
- widget->allocation.y = allocation->y;
- widget->allocation.width = MAX (1, allocation->width);
- widget->allocation.height = MAX (1, allocation->height);
-
- /* If the widget is realized, move and resize its window */
- if (GTK_WIDGET_REALIZED (widget))
- {
- gdk_window_move_resize (widget->window,
- allocation->x,
- allocation->y,
- allocation->width,
- allocation->height);
-
- if (image->detail->background_tile_screen_relative)
- {
- GdkWindow *top_level;
- gint top_level_x;
- gint top_level_y;
- gint image_x;
- gint image_y;
-
-
- top_level = gdk_window_get_toplevel (widget->window);
- g_assert (top_level != NULL);
-
- gdk_window_get_origin (top_level, &top_level_x, &top_level_y);
- gdk_window_get_origin (widget->window, &image_x, &image_y);
-
-#if 0
- g_print ("2 %p:top_level = (%d,%d), %p:image = (%d,%d), diff = (%d,%d)\n",
- top_level,
- top_level_x,
- top_level_y,
- widget->window,
- image_x,
- image_y,
- top_level_x - image_x,
- top_level_y - image_y);
-#endif
-
- image->detail->background_tile_origin.x = ABS (top_level_x - image_x);
- image->detail->background_tile_origin.y = ABS (top_level_y - image_y);
- }
- }
-
- ensure_buffer_size (image, allocation->width, allocation->height);
-
- switch (image->detail->background_type)
- {
- case NAUTILUS_IMAGE_BACKGROUND_PIXBUF:
- if (image->detail->background_pixbuf != NULL)
- {
- nautilus_gdk_pixbuf_tile (image->detail->buffer,
- image->detail->background_pixbuf,
- gdk_pixbuf_get_width (image->detail->background_pixbuf),
- gdk_pixbuf_get_height (image->detail->background_pixbuf),
- image->detail->background_tile_origin.x,
- image->detail->background_tile_origin.y);
- }
- break;
-
- case NAUTILUS_IMAGE_BACKGROUND_SOLID:
- nautilus_gdk_pixbuf_set_to_color (image->detail->buffer, image->detail->background_color);
- break;
- }
-
- if (image ->detail->pixbuf != NULL)
- {
- switch (image->detail->placement_type)
- {
- case NAUTILUS_IMAGE_PLACEMENT_CENTER:
- {
- gint x;
- gint y;
-
- x = (widget->allocation.width - gdk_pixbuf_get_width (image->detail->pixbuf)) / 2;
- y = (widget->allocation.height - gdk_pixbuf_get_height (image->detail->pixbuf)) / 2;
-
- gdk_pixbuf_composite (image->detail->pixbuf,
- image->detail->buffer,
- x,
- y,
- gdk_pixbuf_get_width (image->detail->pixbuf),
- gdk_pixbuf_get_height (image->detail->pixbuf),
- (double) x,
- (double) y,
- 1.0,
- 1.0,
- GDK_INTERP_BILINEAR,
- image->detail->overall_alpha);
- }
- break;
-
- case NAUTILUS_IMAGE_PLACEMENT_TILE:
- {
- nautilus_gdk_pixbuf_tile_alpha (image->detail->buffer,
- image->detail->pixbuf,
- gdk_pixbuf_get_width (image->detail->pixbuf),
- gdk_pixbuf_get_height (image->detail->pixbuf),
- 0,
- 0,
- GDK_INTERP_BILINEAR,
- image->detail->overall_alpha);
- }
- break;
- }
- }
-
- if (image ->detail->label_text != NULL)
- {
- GtkRequisition text_size;
- gint x;
- gint y;
- ArtIRect text_rect;
-
- g_assert (image->detail->label_font != NULL);
-
- gdk_string_dimensions (image->detail->label_font,
- image ->detail->label_text,
- &text_size);
-
- x = widget->allocation.width - text_size.width - image->detail->right_offset;
- y = image->detail->top_offset;
-
-// x = (widget->allocation.width - text_size.width) / 2;
-// y = (widget->allocation.height - text_size.height) / 2;
-
- text_rect.x0 = x;
- text_rect.y0 = y;
- text_rect.x1 = x + text_size.width;
- text_rect.y1 = y + text_size.height;
-
-/* FIXME bugzilla.eazel.com xxxx:
- * Need to be able to pass in a rgb colot into the draw_text function.
- */
- nautilus_gdk_pixbuf_draw_text (image->detail->buffer,
- image->detail->label_font,
- 1.0,
- &text_rect,
- image->detail->label_text,
- NAUTILUS_RGB_COLOR_BLACK,
- image->detail->overall_alpha);
- }
-}
-
-static void
-nautilus_image_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- GtkRequisition pixbuf_size;
- GtkRequisition text_size;
- NautilusImage *image;
+ guint pixbuf_width = 0;
+ guint pixbuf_height = 0;
g_return_if_fail (widget != NULL);
g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
g_return_if_fail (requisition != NULL);
image = NAUTILUS_IMAGE (widget);
-
- requisition->width = 10;
- requisition->height = 10;
- pixbuf_size.width = 0;
- pixbuf_size.height = 0;
- text_size.width = 0;
- text_size.height = 0;
-
- if (image ->detail->pixbuf != NULL)
- {
- pixbuf_size.width = gdk_pixbuf_get_width (image->detail->pixbuf);
- pixbuf_size.height = gdk_pixbuf_get_height (image->detail->pixbuf);
+ if (image->detail->pixbuf != NULL) {
+ pixbuf_width = gdk_pixbuf_get_width (image->detail->pixbuf);
+ pixbuf_height = gdk_pixbuf_get_height (image->detail->pixbuf);
}
- if (image ->detail->label_text != NULL)
- {
- g_assert (image->detail->label_font != NULL);
-
- gdk_string_dimensions (image->detail->label_font,
- image ->detail->label_text,
- &text_size);
- }
-
- requisition->width =
- MAX (pixbuf_size.width, text_size.width) +
- image->detail->extra_width;
-
- requisition->height =
- MAX (pixbuf_size.height, text_size.height) +
- image->detail->extra_height;
-}
-
-static void
-nautilus_image_map (GtkWidget *widget)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
-
- GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
-
- image = NAUTILUS_IMAGE (widget);
-
- gdk_window_show (widget->window);
-}
-
-static void
-nautilus_image_unmap (GtkWidget *widget)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
-
- GTK_WIDGET_UNSET_FLAGS(widget, GTK_MAPPED);
-
- image = NAUTILUS_IMAGE (widget);
-
- gdk_window_hide (widget->window);
-}
-
-static gint
-nautilus_image_expose (GtkWidget *widget, GdkEventExpose *event)
-{
- NautilusImage *image;
-
- g_return_val_if_fail (widget != NULL, FALSE);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (widget), FALSE);
-
- image = NAUTILUS_IMAGE (widget);
-
- nautilus_image_draw (widget, &event->area);
-
- return TRUE;
+ requisition->width = MAX (2, pixbuf_width);
+ requisition->height = MAX (2, pixbuf_height);
}
/* Private NautilusImage things */
static void
-ensure_buffer_size (NautilusImage *image,
- guint new_width,
- guint new_height)
-{
- guint old_width = 0;
- guint old_height = 0;
-
- g_assert (image != NULL);
- g_assert (NAUTILUS_IS_IMAGE (image));
-
- if (new_width == 0 || new_height == 0) {
- return;
- }
-
- if (image->detail->buffer != NULL) {
- old_width = gdk_pixbuf_get_width (image->detail->buffer);
- old_height = gdk_pixbuf_get_height (image->detail->buffer);
- }
-
- if (old_width < new_width || old_height < new_height) {
- GdkPixbuf *new_pixbuf = NULL;
-
- new_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, new_width, new_height);
-
- if (image->detail->buffer) {
- gdk_pixbuf_unref (image->detail->buffer);
- }
-
- image->detail->buffer = new_pixbuf;
- }
-}
-
-static GdkGC *
-nautilus_gdk_create_copy_area_gc (GdkWindow *window)
-{
- GdkGC *copy_area_gc;
-
- g_return_val_if_fail (window != NULL, NULL);
-
- copy_area_gc = gdk_gc_new (window);
-
- gdk_gc_set_function (copy_area_gc, GDK_COPY);
-
- return copy_area_gc;
-}
-
-static void
-nautilus_gdk_pixbuf_render_to_drawable (const GdkPixbuf *pixbuf,
- GdkDrawable *drawable,
- GdkGC *gc,
- const GdkPoint *source_point,
- const GdkRectangle *destination_area,
- GdkRgbDither dither)
-{
- GdkPoint src;
- GdkRectangle dst;
- GdkPoint end;
-
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (drawable != NULL);
- g_return_if_fail (gc != NULL);
- g_return_if_fail (source_point != NULL);
- g_return_if_fail (destination_area != NULL);
- g_return_if_fail (destination_area->width > 0);
- g_return_if_fail (destination_area->height > 0);
- g_return_if_fail (source_point->x >= 0);
- g_return_if_fail (source_point->y >= 0);
-
- g_assert (gdk_pixbuf_get_width (pixbuf) > 0);
- g_assert (gdk_pixbuf_get_height (pixbuf) > 0);
-
- src = *source_point;
- dst = *destination_area;
-
- /* Clip to the left edge of the drawable */
- if (dst.x < 0)
- {
- src.x += ABS (dst.x);
- dst.x = 0;
- }
-
- /* Clip to the top edge of the drawable */
- if (dst.y < 0)
- {
- src.y += ABS (dst.y);
- dst.y = 0;
- }
-
- end.x = src.x + dst.width;
- end.y = src.y + dst.height;
-
- if (end.x >= gdk_pixbuf_get_width (pixbuf))
- {
- g_assert (dst.width >= (end.x - gdk_pixbuf_get_width (pixbuf)));
-
- dst.width -= (end.x - gdk_pixbuf_get_width (pixbuf));
- }
-
- if (end.y >= gdk_pixbuf_get_height (pixbuf))
- {
- g_assert (dst.height >= (end.y - gdk_pixbuf_get_height (pixbuf)));
-
- dst.height -= (end.y - gdk_pixbuf_get_height (pixbuf));
- }
-
- if (gdk_pixbuf_get_has_alpha (pixbuf)) {
- gdk_pixbuf_render_to_drawable_alpha ((GdkPixbuf *) pixbuf,
- drawable,
- src.x,
- src.y,
- dst.x,
- dst.y,
- dst.width,
- dst.height,
- GDK_PIXBUF_ALPHA_FULL,
- 128,
- dither,
- 0,
- 0);
-
- } else {
- gdk_pixbuf_render_to_drawable ((GdkPixbuf *) pixbuf,
- drawable,
- gc,
- src.x,
- src.y,
- dst.x,
- dst.y,
- dst.width,
- dst.height,
- dither,
- 0,
- 0);
- }
-}
-
-static void
-nautilus_gdk_pixbuf_render_to_pixbuf (const GdkPixbuf *pixbuf,
- GdkPixbuf *destination_pixbuf,
- const GdkPoint *source_point,
- const GdkRectangle *destination_area)
-{
- GdkPoint src;
- GdkRectangle dst;
- GdkPoint end;
-
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (destination_pixbuf != NULL);
- g_return_if_fail (source_point != NULL);
- g_return_if_fail (source_point->x >= 0);
- g_return_if_fail (source_point->y >= 0);
- g_return_if_fail (destination_area != NULL);
- g_return_if_fail (destination_area->width > 0);
- g_return_if_fail (destination_area->height > 0);
-
- src = *source_point;
- dst = *destination_area;
-
- /* Clip to the left edge of the drawable */
- if (dst.x < 0)
- {
- src.x += ABS (dst.x);
- dst.x = 0;
- }
-
- /* Clip to the top edge of the drawable */
- if (dst.y < 0)
- {
- src.y += ABS (dst.y);
- dst.y = 0;
- }
-
- end.x = src.x + dst.width;
- end.y = src.y + dst.height;
-
- if (end.x >= gdk_pixbuf_get_width (pixbuf))
- {
- g_assert (dst.width >= (end.x - gdk_pixbuf_get_width (pixbuf)));
-
- dst.width -= (end.x - gdk_pixbuf_get_width (pixbuf));
- }
-
- if (end.y >= gdk_pixbuf_get_height (pixbuf))
- {
- g_assert (dst.height >= (end.y - gdk_pixbuf_get_height (pixbuf)));
-
- dst.height -= (end.y - gdk_pixbuf_get_height (pixbuf));
- }
-
- gdk_pixbuf_copy_area ((GdkPixbuf *) pixbuf,
- src.x,
- src.y,
- dst.width,
- dst.height,
- destination_pixbuf,
- dst.x,
- dst.y);
-}
-
-static void
-nautilus_gdk_pixbuf_render_to_pixbuf_alpha (const GdkPixbuf *pixbuf,
- GdkPixbuf *destination_pixbuf,
- const GdkRectangle *destination_area,
- GdkInterpType interpolation_mode,
- guchar overall_alpha)
+render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget, GdkPixbuf *buffer)
{
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (destination_pixbuf != NULL);
- g_return_if_fail (destination_area != NULL);
- g_return_if_fail (destination_area->width > 0);
- g_return_if_fail (destination_area->height > 0);
-
- gdk_pixbuf_composite (pixbuf,
- destination_pixbuf,
- destination_area->x,
- destination_area->y,
- destination_area->width,
- destination_area->height,
- (double) destination_area->x,
- (double) destination_area->y,
- 1.0,
- 1.0,
- interpolation_mode,
- overall_alpha);
-}
+ NautilusImage *image;
+ GtkWidget *widget;
-static void
-gdk_string_dimensions (const GdkFont *font,
- const gchar *string,
- GtkRequisition *size)
-{
- g_return_if_fail (font != NULL);
- g_return_if_fail (size != NULL);
+ g_return_if_fail (NAUTILUS_IS_IMAGE (buffered_widget));
+ g_return_if_fail (buffer != NULL);
- size->width = 0;
- size->height = 0;
+ image = NAUTILUS_IMAGE (buffered_widget);
+ widget = GTK_WIDGET (buffered_widget);
- if (string && (strlen (string) > 0))
- {
- gint width;
- gint lbearing;
- gint rbearing;
- gint ascent;
- gint descent;
-
- gdk_text_extents ((GdkFont *) font,
- string,
- strlen (string),
- &lbearing,
- &rbearing,
- &width,
- &ascent,
- &descent);
-
- size->width = width;
- size->height = ascent + descent;
- }
-}
+ if (image->detail->pixbuf != NULL) {
+ gint x;
+ gint y;
+ guint width = gdk_pixbuf_get_width (image->detail->pixbuf);
+ guint height = gdk_pixbuf_get_height (image->detail->pixbuf);
-static void
-nautilus_gdk_pixbuf_set_to_color (GdkPixbuf *pixbuf,
- guint32 color)
-{
- guchar *pixels;
- guint width;
- guint height;
- guint rowstride;
- guint x;
- guint y;
- guchar *offset;
-
- g_return_if_fail (pixbuf != NULL);
-
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
- rowstride = gdk_pixbuf_get_rowstride (pixbuf);
- pixels = gdk_pixbuf_get_pixels (pixbuf);
-
- if (gdk_pixbuf_get_has_alpha (pixbuf))
- {
- for (y = 0; y < height; y++)
- {
- offset = pixels + y * rowstride;
-
- for (x = 0; x < width; x++)
- {
- *offset++ = NAUTILUS_RGBA_COLOR_GET_R (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_G (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_B (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_A (color);
- }
+ if (width <= widget->allocation.width) {
+ x = (widget->allocation.width - width) / 2;
}
- }
- else
- {
- for (y = 0; y < height; y++)
- {
- offset = pixels + y * rowstride;
-
- for (x = 0; x < width; x++)
- {
- *offset++ = NAUTILUS_RGBA_COLOR_GET_R (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_G (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_B (color);
- }
+ else {
+ x = - (width - widget->allocation.width) / 2;
}
- }
-}
-
-/* FIXME bugzilla.eazel.com 1612:
- * Tile origin should be respected. Should be fixed when I use NautilusBackground.
- */
-static void
-nautilus_gdk_pixbuf_tile (GdkPixbuf *pixbuf,
- const GdkPixbuf *tile_pixbuf,
- guint tile_width,
- guint tile_height,
- gint tile_origin_x,
- gint tile_origin_y)
-{
- gint x;
- gint y;
- guchar *pixels;
- guchar *tile_pixels;
- guint num_ver_iterations;
- guint num_hor_iterations;
- guint i;
- guint j;
- guint width;
- guint height;
-
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (tile_pixbuf != NULL);
- g_return_if_fail (tile_width <= gdk_pixbuf_get_width (tile_pixbuf));
- g_return_if_fail (tile_height <= gdk_pixbuf_get_height (tile_pixbuf));
- g_return_if_fail (gdk_pixbuf_get_pixels (pixbuf) != NULL);
- g_return_if_fail (gdk_pixbuf_get_pixels (tile_pixbuf) != NULL);
-
- pixels = gdk_pixbuf_get_pixels (pixbuf);
- tile_pixels = gdk_pixbuf_get_pixels (tile_pixbuf);
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
-
- num_ver_iterations = ceil (height / tile_height) + 1;
- num_hor_iterations = ceil (width / tile_width) + 1;
-
- y = 0;
- for (j = 0; j < num_ver_iterations; j++)
- {
- x = 0;
-
- for (i = 0; i < num_hor_iterations; i++)
- {
- guint copy_width;
- guint copy_height;
- gint dst_x;
- gint dst_y;
- gint dst_x2;
- gint dst_y2;
-
- dst_x = x;
- dst_y = y;
-
- copy_width = tile_width;
- copy_height = tile_height;
-
- dst_x2 = dst_x + copy_width;
- dst_y2 = dst_y + copy_height;
-
- if (dst_x2 > width)
- {
- copy_width -= (dst_x2 - width);
- }
-
- if (dst_y2 > height)
- {
- copy_height -= (dst_y2 - height);
- }
-
- if (copy_width > 0 && copy_height > 0)
- {
- GdkPoint source_point;
- GdkRectangle destination_area;
-
- source_point.x = 0;
- source_point.y = 0;
-
- destination_area.x = dst_x;
- destination_area.y = dst_y;
- destination_area.width = copy_width;
- destination_area.height = copy_height;
-
- nautilus_gdk_pixbuf_render_to_pixbuf (tile_pixbuf,
- pixbuf,
- &source_point,
- &destination_area);
- }
-
- x += tile_width;
+ if (height <= widget->allocation.height) {
+ y = (widget->allocation.height - height) / 2;
}
-
- y += tile_height;
- }
-}
-
-static void
-nautilus_gdk_pixbuf_tile_alpha (GdkPixbuf *pixbuf,
- const GdkPixbuf *tile_pixbuf,
- guint tile_width,
- guint tile_height,
- gint tile_origin_x,
- gint tile_origin_y,
- GdkInterpType interpolation_mode,
- guchar overall_alpha)
-{
- gint x;
- gint y;
- guchar *pixels;
- guchar *tile_pixels;
- guint num_ver_iterations;
- guint num_hor_iterations;
- guint i;
- guint j;
- guint width;
- guint height;
-
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (tile_pixbuf != NULL);
- g_return_if_fail (tile_width <= gdk_pixbuf_get_width (tile_pixbuf));
- g_return_if_fail (tile_height <= gdk_pixbuf_get_height (tile_pixbuf));
- g_return_if_fail (gdk_pixbuf_get_pixels (pixbuf) != NULL);
- g_return_if_fail (gdk_pixbuf_get_pixels (tile_pixbuf) != NULL);
-
- pixels = gdk_pixbuf_get_pixels (pixbuf);
- tile_pixels = gdk_pixbuf_get_pixels (tile_pixbuf);
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
-
- num_ver_iterations = ceil (height / tile_height) + 1;
- num_hor_iterations = ceil (width / tile_width) + 1;
-
- y = 0;
-
- for (j = 0; j < num_ver_iterations; j++)
- {
- x = 0;
-
- for (i = 0; i < num_hor_iterations; i++)
- {
- guint copy_width;
- guint copy_height;
- gint dst_x;
- gint dst_y;
- gint dst_x2;
- gint dst_y2;
-
- dst_x = x;
- dst_y = y;
-
- copy_width = tile_width;
- copy_height = tile_height;
-
- dst_x2 = dst_x + copy_width;
- dst_y2 = dst_y + copy_height;
-
- if (dst_x2 > width)
- {
- copy_width -= (dst_x2 - width);
- }
-
- if (dst_y2 > height)
- {
- copy_height -= (dst_y2 - height);
- }
-
- if (copy_width > 0 && copy_height > 0)
- {
- GdkRectangle destination_area;
-
- destination_area.x = dst_x;
- destination_area.y = dst_y;
- destination_area.width = copy_width;
- destination_area.height = copy_height;
-
- nautilus_gdk_pixbuf_render_to_pixbuf_alpha (tile_pixbuf,
- pixbuf,
- &destination_area,
- interpolation_mode,
- overall_alpha);
- }
-
- x += tile_width;
+ else {
+ y = - (height - widget->allocation.height) / 2;
}
- y += tile_height;
+ gdk_pixbuf_composite (image->detail->pixbuf,
+ buffer,
+ x,
+ y,
+ width,
+ height,
+ (double) x,
+ (double) y,
+ 1.0,
+ 1.0,
+ GDK_INTERP_BILINEAR,
+ image->detail->overall_alpha);
}
}
@@ -1211,121 +297,14 @@ nautilus_image_new (void)
}
void
-nautilus_image_set_background_pixbuf (NautilusImage *image, GdkPixbuf *background_pixbuf)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- if (background_pixbuf != image->detail->background_pixbuf)
- {
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->background_pixbuf);
-
- NAUTILUS_GDK_PIXBUF_REF_IF (background_pixbuf);
-
- image->detail->background_pixbuf = background_pixbuf;
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-GdkPixbuf*
-nautilus_image_get_background_pixbuf (const NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, NULL);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
-
- NAUTILUS_GDK_PIXBUF_REF_IF (image->detail->background_pixbuf);
-
- return image->detail->background_pixbuf;
-}
-
-void
-nautilus_image_set_background_type (NautilusImage *image, NautilusImageBackgroundType background_type)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- if (background_type == image->detail->background_type)
- {
- return;
- }
-
- image->detail->background_type = background_type;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-NautilusImageBackgroundType
-nautilus_image_get_background_type (const NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, 0);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
-
- return image->detail->background_type;
-}
-
-void
-nautilus_image_set_background_color (NautilusImage *image, guint32 background_color)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- if (background_color == image->detail->background_color)
- {
- return;
- }
-
- image->detail->background_color = background_color;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-guint32
-nautilus_image_get_background_color (const NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, 0);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
-
- return image->detail->background_color;
-}
-
-void
-nautilus_image_set_placement_type (NautilusImage *image, NautilusImagePlacementType placement_type)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- if (placement_type == image->detail->placement_type)
- {
- return;
- }
-
- image->detail->placement_type = placement_type;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-NautilusImagePlacementType
-nautilus_image_get_placement_type (const NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, 0);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
-
- return image->detail->placement_type;
-}
-
-void
nautilus_image_set_pixbuf (NautilusImage *image, GdkPixbuf *pixbuf)
{
- g_return_if_fail (image != NULL);
g_return_if_fail (NAUTILUS_IS_IMAGE (image));
if (pixbuf != image->detail->pixbuf)
{
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->pixbuf);
-
- NAUTILUS_GDK_PIXBUF_REF_IF (pixbuf);
-
+ nautilus_gdk_pixbuf_unref_if_not_null (image->detail->pixbuf);
+ nautilus_gdk_pixbuf_ref_if_not_null (pixbuf);
image->detail->pixbuf = pixbuf;
}
@@ -1335,145 +314,22 @@ nautilus_image_set_pixbuf (NautilusImage *image, GdkPixbuf *pixbuf)
GdkPixbuf*
nautilus_image_get_pixbuf (const NautilusImage *image)
{
- g_return_val_if_fail (image != NULL, NULL);
g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
- NAUTILUS_GDK_PIXBUF_REF_IF (image->detail->pixbuf);
+ nautilus_gdk_pixbuf_ref_if_not_null (image->detail->pixbuf);
return image->detail->pixbuf;
}
void
nautilus_image_set_overall_alpha (NautilusImage *image,
- guchar pixbuf_alpha)
+ guchar pixbuf_alpha)
{
- g_return_if_fail (image != NULL);
g_return_if_fail (NAUTILUS_IS_IMAGE (image));
image->detail->overall_alpha = pixbuf_alpha;
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_label_text (NautilusImage *image,
- const gchar *text)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- g_free (image->detail->label_text);
+ nautilus_buffered_widget_clear_buffer (NAUTILUS_BUFFERED_WIDGET (image));
- image->detail->label_text = text ? g_strdup (text) : NULL;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-gchar*
-nautilus_image_get_label_text (NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, NULL);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
-
- return image->detail->label_text ? g_strdup (image->detail->label_text) : NULL;
-}
-
-void
-nautilus_image_set_label_font (NautilusImage *image,
- GdkFont *font)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- NAUTILUS_GDK_FONT_UNREF_IF (image->detail->label_font);
-
- image->detail->label_font = font;
-
- NAUTILUS_GDK_FONT_REF_IF (image->detail->label_font);
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-GdkFont *
-nautilus_image_get_label_font (NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, NULL);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
-
- NAUTILUS_GDK_FONT_REF_IF (image->detail->label_font);
-
- return image->detail->label_font;
+ gtk_widget_queue_draw (GTK_WIDGET (image));
}
-
-void
-nautilus_image_set_left_offset (NautilusImage *image,
- guint left_offset)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->left_offset = left_offset;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_right_offset (NautilusImage *image,
- guint right_offset)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->right_offset = right_offset;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_top_offset (NautilusImage *image,
- guint top_offset)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->top_offset = top_offset;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_bottom_offset (NautilusImage *image,
- guint bottom_offset)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->bottom_offset = bottom_offset;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_extra_width (NautilusImage *image,
- guint extra_width)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->extra_width = extra_width;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_extra_height (NautilusImage *image,
- guint extra_height)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->extra_height = extra_height;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
diff --git a/libnautilus-extensions/nautilus-image.h b/libnautilus-extensions/nautilus-image.h
index d304b14b5..41a41ed78 100644
--- a/libnautilus-extensions/nautilus-image.h
+++ b/libnautilus-extensions/nautilus-image.h
@@ -1,6 +1,6 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* nautilus-image.h - A widget to display a composited pixbuf.
+/* nautilus-image.h - A widget to display a alpha composited pixbufs.
Copyright (C) 1999, 2000 Eazel, Inc.
@@ -22,16 +22,25 @@
Authors: Ramiro Estrugo <ramiro@eazel.com>
*/
+/* NautilusImage is a widget that is capable of displaying alpha composited
+ * pixbufs over complex backgrounds. The background can be installed as
+ * NautilusBackground on a NautilusImage widget or any of its ancestors.
+ *
+ * The background can also be that provided by the GtkStyle attatched to the
+ * widget.
+ *
+ * The best background will automatically be found and used by the widget.
+ *
+ */
+
#ifndef NAUTILUS_IMAGE_H
#define NAUTILUS_IMAGE_H
-#include <gtk/gtkmisc.h>
-#include <libgnome/gnome-defs.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <libnautilus-extensions/nautilus-buffered-widget.h>
+#include <libnautilus-extensions/nautilus-scalable-font.h>
-/* NautilusImage is GtkWidget that can display a GdkPixbuf. This pixbuf
- * will be composited with full alpha support on wither a solid background
- * or a background pixbuf.
+/* NautilusImage is GtkWidget that draws a string using the high quality
+ * anti aliased librsvg/freetype.
*/
BEGIN_GNOME_DECLS
@@ -42,87 +51,31 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_IS_IMAGE(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_IMAGE))
#define NAUTILUS_IS_IMAGE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_IMAGE))
-typedef struct _NautilusImage NautilusImage;
-typedef struct _NautilusImageClass NautilusImageClass;
-typedef struct _NautilusImageDetail NautilusImageDetail;
+typedef struct _NautilusImage NautilusImage;
+typedef struct _NautilusImageClass NautilusImageClass;
+typedef struct _NautilusImageDetail NautilusImageDetail;
struct _NautilusImage
{
/* Superclass */
- GtkMisc misc;
+ NautilusBufferedWidget buffered_widget;
/* Private things */
- NautilusImageDetail *detail;
+ NautilusImageDetail *detail;
};
struct _NautilusImageClass
{
- GtkMiscClass parent_class;
+ NautilusBufferedWidgetClass parent_class;
};
-typedef enum
-{
- NAUTILUS_IMAGE_PLACEMENT_TILE,
- NAUTILUS_IMAGE_PLACEMENT_CENTER
-} NautilusImagePlacementType;
-
-typedef enum
-{
- NAUTILUS_IMAGE_BACKGROUND_PIXBUF,
- NAUTILUS_IMAGE_BACKGROUND_SOLID,
-} NautilusImageBackgroundType;
-
-/* Pack RGBA components */
-#define NAUTILUS_RGBA_COLOR_PACK(_r, _g, _b, _a) \
-( ((_a) << 24) | \
- ((_r) << 16) | \
- ((_g) << 8) | \
- ((_b) << 0) )
-
-/* Access RGBA components */
-#define NAUTILUS_RGBA_COLOR_GET_R(_color) (((_color) >> 16) & 0xff)
-#define NAUTILUS_RGBA_COLOR_GET_G(_color) (((_color) >> 8) & 0xff)
-#define NAUTILUS_RGBA_COLOR_GET_B(_color) (((_color) >> 0) & 0xff)
-#define NAUTILUS_RGBA_COLOR_GET_A(_color) (((_color) >> 24) & 0xff)
-
-GtkType nautilus_image_get_type (void);
-GtkWidget * nautilus_image_new (void);
-void nautilus_image_set_background_pixbuf (NautilusImage *image,
- GdkPixbuf *background);
-GdkPixbuf* nautilus_image_get_background_pixbuf (const NautilusImage *image);
-void nautilus_image_set_background_type (NautilusImage *image,
- NautilusImageBackgroundType background_type);
-NautilusImageBackgroundType nautilus_image_get_background_type (const NautilusImage *image);
-void nautilus_image_set_placement_type (NautilusImage *image,
- NautilusImagePlacementType placement);
-NautilusImagePlacementType nautilus_image_get_placement_type (const NautilusImage *image);
-void nautilus_image_set_background_color (NautilusImage *image,
- guint32 color);
-guint32 nautilus_image_get_background_color (const NautilusImage *image);
-void nautilus_image_set_pixbuf (NautilusImage *image,
- GdkPixbuf *pixbuf);
-GdkPixbuf* nautilus_image_get_pixbuf (const NautilusImage *image);
-void nautilus_image_set_overall_alpha (NautilusImage *image,
- guchar pixbuf_alpha);
-void nautilus_image_set_label_text (NautilusImage *image,
- const gchar *text);
-gchar* nautilus_image_get_label_text (NautilusImage *image);
-void nautilus_image_set_label_font (NautilusImage *image,
- GdkFont *font);
-GdkFont* nautilus_image_get_label_font (NautilusImage *image);
-void nautilus_image_set_left_offset (NautilusImage *image,
- guint left_offset);
-void nautilus_image_set_right_offset (NautilusImage *image,
- guint right_offset);
-void nautilus_image_set_top_offset (NautilusImage *image,
- guint top_offset);
-void nautilus_image_set_bottom_offset (NautilusImage *image,
- guint bottom_offset);
-void nautilus_image_set_extra_width (NautilusImage *image,
- guint extra_width);
-void nautilus_image_set_extra_height (NautilusImage *image,
- guint extra_width);
-
+GtkType nautilus_image_get_type (void);
+GtkWidget *nautilus_image_new (void);
+void nautilus_image_set_pixbuf (NautilusImage *image,
+ GdkPixbuf *pixbuf);
+GdkPixbuf* nautilus_image_get_pixbuf (const NautilusImage *image);
+void nautilus_image_set_overall_alpha (NautilusImage *image,
+ guchar pixbuf_alpha);
END_GNOME_DECLS
diff --git a/libnautilus-extensions/nautilus-label.c b/libnautilus-extensions/nautilus-label.c
new file mode 100644
index 000000000..f756b36ec
--- /dev/null
+++ b/libnautilus-extensions/nautilus-label.c
@@ -0,0 +1,569 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-label.c - A widget to display a anti aliased text.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+#include "nautilus-label.h"
+
+#include "nautilus-gtk-macros.h"
+#include "nautilus-gdk-extensions.h"
+#include "nautilus-gdk-pixbuf-extensions.h"
+#include "nautilus-string.h"
+
+/* Arguments */
+enum
+{
+ ARG_0,
+ ARG_BACKGROUND_COLOR,
+ ARG_BACKGROUND_TYPE,
+ ARG_LABEL,
+ ARG_PLACEMENT_TYPE,
+};
+
+/* Detail member struct */
+struct _NautilusLabelDetail
+{
+ /* Text */
+ char *text;
+ guint32 text_color;
+ guchar text_alpha;
+ guint text_width;
+ guint text_height;
+ GtkJustification text_justification;
+ guint line_offset;
+
+ /* Font */
+ NautilusScalableFont *font;
+ guint font_size;
+
+ /* Text lines */
+ char **text_lines;
+ guint *text_line_widths;
+ guint *text_line_heights;
+ guint num_text_lines;
+ guint max_text_line_width;
+ guint total_text_line_height;
+};
+
+/* GtkObjectClass methods */
+static void nautilus_label_initialize_class (NautilusLabelClass *label_class);
+static void nautilus_label_initialize (NautilusLabel *label);
+static void nautilus_label_destroy (GtkObject *object);
+static void nautilus_label_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+static void nautilus_label_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+
+/* GtkWidgetClass methods */
+static void nautilus_label_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+
+/* NautilusBufferedWidgetClass methods */
+static void render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
+ GdkPixbuf *buffer);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusLabel, nautilus_label, NAUTILUS_TYPE_BUFFERED_WIDGET)
+
+/* Class init methods */
+static void
+nautilus_label_initialize_class (NautilusLabelClass *label_class)
+{
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (label_class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (label_class);
+ NautilusBufferedWidgetClass *buffered_widget_class = NAUTILUS_BUFFERED_WIDGET_CLASS (label_class);
+
+#if 0
+ /* Arguments */
+ gtk_object_add_arg_type ("NautilusLabel::placement_type",
+ GTK_TYPE_ENUM,
+ GTK_ARG_READWRITE,
+ ARG_PLACEMENT_TYPE);
+
+ gtk_object_add_arg_type ("NautilusLabel::background_type",
+ GTK_TYPE_ENUM,
+ GTK_ARG_READWRITE,
+ ARG_BACKGROUND_TYPE);
+
+ gtk_object_add_arg_type ("NautilusLabel::background_color",
+ GTK_TYPE_UINT,
+ GTK_ARG_READWRITE,
+ ARG_BACKGROUND_COLOR);
+
+ gtk_object_add_arg_type ("NautilusLabel::label",
+ GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE,
+ ARG_LABEL);
+#endif
+
+ /* GtkObjectClass */
+ object_class->destroy = nautilus_label_destroy;
+ object_class->set_arg = nautilus_label_set_arg;
+ object_class->get_arg = nautilus_label_get_arg;
+
+ /* GtkWidgetClass */
+ widget_class->size_request = nautilus_label_size_request;
+
+ /* NautilusBufferedWidgetClass */
+ buffered_widget_class->render_buffer_pixbuf = render_buffer_pixbuf;
+}
+
+void
+nautilus_label_initialize (NautilusLabel *label)
+{
+ label->detail = g_new (NautilusLabelDetail, 1);
+
+ label->detail->text = NULL;
+
+ label->detail->font = nautilus_scalable_font_get_default_font ();
+ label->detail->font_size = 48;
+
+ label->detail->text_color = NAUTILUS_RGBA_COLOR_PACK (0, 0, 0, 255);
+ label->detail->text_alpha = 255;
+ label->detail->text_width = 0;
+ label->detail->text_height = 0;
+ label->detail->text_justification = GTK_JUSTIFY_CENTER;
+
+ label->detail->num_text_lines = 0;
+ label->detail->max_text_line_width = 0;
+ label->detail->total_text_line_height = 0;
+ label->detail->text_lines = NULL;
+ label->detail->text_line_widths = NULL;
+ label->detail->text_line_heights = NULL;
+
+ label->detail->line_offset = 2;
+}
+
+/* GtkObjectClass methods */
+static void
+nautilus_label_destroy (GtkObject *object)
+{
+ NautilusLabel *label;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (object));
+
+ label = NAUTILUS_LABEL (object);
+
+ g_free (label->detail->text);
+
+ g_strfreev (label->detail->text_lines);
+ g_free (label->detail->text_line_widths);
+ g_free (label->detail->text_line_heights);
+
+ g_free (label->detail);
+
+ /* Chain destroy */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static void
+nautilus_label_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ NautilusLabel *label;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (object));
+
+ label = NAUTILUS_LABEL (object);
+
+#if 0
+ switch (arg_id)
+ {
+ case ARG_PLACEMENT_TYPE:
+ label->detail->placement_type = GTK_VALUE_ENUM (*arg);
+ break;
+
+ case ARG_BACKGROUND_TYPE:
+ label->detail->background_type = GTK_VALUE_ENUM (*arg);
+ break;
+
+ case ARG_BACKGROUND_COLOR:
+ label->detail->background_color = GTK_VALUE_UINT (*arg);
+ break;
+
+ case ARG_LABEL:
+ nautilus_label_set_pixbuf (label, (GdkPixbuf*) GTK_VALUE_OBJECT (*arg));
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+#endif
+}
+
+static void
+nautilus_label_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ NautilusLabel *label;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (object));
+
+ label = NAUTILUS_LABEL (object);
+
+#if 0
+ switch (arg_id)
+ {
+ case ARG_PLACEMENT_TYPE:
+ GTK_VALUE_ENUM (*arg) = label->detail->placement_type;
+ break;
+
+ case ARG_BACKGROUND_TYPE:
+ GTK_VALUE_ENUM (*arg) = label->detail->background_type;
+ break;
+
+ case ARG_BACKGROUND_COLOR:
+ GTK_VALUE_UINT (*arg) = label->detail->background_color;
+ break;
+
+ case ARG_LABEL:
+ GTK_VALUE_OBJECT (*arg) = (GtkObject *) nautilus_label_get_pixbuf (label);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+#endif
+}
+
+/* GtkWidgetClass methods */
+static void
+nautilus_label_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ NautilusLabel *label;
+ guint text_width = 0;
+ guint text_height = 0;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (widget));
+ g_return_if_fail (requisition != NULL);
+
+ label = NAUTILUS_LABEL (widget);
+
+ if (label->detail->num_text_lines > 0) {
+ text_width = label->detail->max_text_line_width;
+ text_height = label->detail->total_text_line_height;
+
+ text_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
+ }
+
+ requisition->width = MAX (2, text_width);
+ requisition->height = MAX (2, text_height);
+}
+
+/* Private NautilusLabel things */
+static void
+render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget, GdkPixbuf *buffer)
+{
+ NautilusLabel *label;
+ GtkWidget *widget;
+ ArtIRect area;
+ guint total_text_width;
+ guint total_text_height;
+
+
+ g_return_if_fail (NAUTILUS_IS_LABEL (buffered_widget));
+ g_return_if_fail (buffer != NULL);
+
+ label = NAUTILUS_LABEL (buffered_widget);
+
+ if (label->detail->num_text_lines == 0) {
+ return;
+ }
+
+ widget = GTK_WIDGET (buffered_widget);
+
+ total_text_width = label->detail->max_text_line_width;
+ total_text_height = label->detail->total_text_line_height;
+ total_text_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
+
+
+ if (total_text_width <= widget->allocation.width) {
+ area.x0 = (widget->allocation.width - total_text_width) / 2;
+ }
+ else {
+ area.x0 = - (total_text_width - widget->allocation.width) / 2;
+ }
+
+ if (total_text_height <= widget->allocation.height) {
+ area.y0 = (widget->allocation.height - total_text_height) / 2;
+ }
+ else {
+ area.y0 = - (total_text_height - widget->allocation.height) / 2;
+ }
+
+ area.x1 = area.x0 + total_text_width;
+ area.y1 = area.y0 + total_text_width;
+
+ if (label->detail->num_text_lines > 0) {
+ nautilus_scalable_font_draw_text_lines (label->detail->font,
+ buffer,
+ &area,
+ label->detail->font_size,
+ label->detail->font_size,
+ (const char **) label->detail->text_lines,
+ label->detail->text_line_widths,
+ label->detail->text_line_heights,
+ label->detail->text_justification,
+ label->detail->num_text_lines,
+ label->detail->line_offset,
+ label->detail->text_color,
+ label->detail->text_alpha);
+ }
+}
+
+/* Public NautilusLabel */
+GtkWidget*
+nautilus_label_new (void)
+{
+ return GTK_WIDGET (gtk_type_new (nautilus_label_get_type ()));
+}
+
+void
+nautilus_label_set_text (NautilusLabel *label,
+ const gchar *text)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+
+ g_free (label->detail->text);
+ label->detail->text = text ? g_strdup (text) : NULL;
+
+ g_strfreev (label->detail->text_lines);
+ g_free (label->detail->text_line_widths);
+ g_free (label->detail->text_line_heights);
+ label->detail->text_lines = NULL;
+ label->detail->text_line_widths = NULL;
+ label->detail->text_line_heights = NULL;
+
+ label->detail->num_text_lines = 0;
+
+ label->detail->max_text_line_width = 0;
+ label->detail->total_text_line_height = 0;
+
+ label->detail->text_lines = NULL;
+
+ if (nautilus_strlen (label->detail->text) > 0) {
+ label->detail->num_text_lines = nautilus_str_count_characters (label->detail->text, '\n') + 1;
+
+ label->detail->text_lines = g_strsplit (label->detail->text, "\n", -1);
+
+ label->detail->text_line_widths = g_new (guint, label->detail->num_text_lines);
+ label->detail->text_line_heights = g_new (guint, label->detail->num_text_lines);
+
+ nautilus_scalable_font_measure_text_lines (label->detail->font,
+ label->detail->font_size,
+ label->detail->font_size,
+ (const char **) label->detail->text_lines,
+ label->detail->num_text_lines,
+ label->detail->text_line_widths,
+ label->detail->text_line_heights,
+ &label->detail->max_text_line_width,
+ &label->detail->total_text_line_height);
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+}
+
+gchar*
+nautilus_label_get_text (NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NULL);
+
+ return label->detail->text ? g_strdup (label->detail->text) : NULL;
+}
+
+void
+nautilus_label_set_font (NautilusLabel *label,
+ NautilusScalableFont *font)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+
+ if (label->detail->font != NULL) {
+ gtk_object_unref (GTK_OBJECT (label->detail->font));
+ label->detail->font = NULL;
+ }
+
+ gtk_object_ref (GTK_OBJECT (font));
+
+ label->detail->font = font;
+
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+}
+
+NautilusScalableFont *
+nautilus_label_get_font (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ if (label->detail->font != NULL) {
+ gtk_object_ref (GTK_OBJECT (label->detail->font));
+ }
+
+ return label->detail->font;
+}
+
+void
+nautilus_label_set_font_size (NautilusLabel *label,
+ guint font_size)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+ g_return_if_fail (font_size > 0);
+
+ if (label->detail->font_size == font_size) {
+ return;
+ }
+
+ label->detail->font_size = font_size;
+
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+}
+
+guint
+nautilus_label_get_font_size (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->font_size;
+}
+
+void
+nautilus_label_set_text_color (NautilusLabel *label,
+ guint32 text_color)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+
+ label->detail->text_color = text_color;
+
+ nautilus_buffered_widget_clear_buffer (NAUTILUS_BUFFERED_WIDGET (label));
+
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+}
+
+guint32
+nautilus_label_get_text_color (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->text_color;
+}
+
+void
+nautilus_label_set_text_alpha (NautilusLabel *label,
+ guchar text_alpha)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+
+ label->detail->text_alpha = text_alpha;
+
+ nautilus_buffered_widget_clear_buffer (NAUTILUS_BUFFERED_WIDGET (label));
+
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+}
+
+guchar
+nautilus_label_get_text_alpha (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->text_alpha;
+}
+
+void
+nautilus_label_set_text_justification (NautilusLabel *label,
+ GtkJustification justification)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+ g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL);
+
+ if (label->detail->text_justification == justification) {
+ return;
+ }
+
+ label->detail->text_justification = justification;
+
+ nautilus_buffered_widget_clear_buffer (NAUTILUS_BUFFERED_WIDGET (label));
+
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+}
+
+GtkJustification
+nautilus_label_get_text_justification (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->text_justification;
+}
+
+/**
+ * nautilus_label_get_line_offset:
+ *
+ * @label: A NautilusLabel
+ *
+ * Change the line offset. Obviously, this is only interesting if the
+ * label is displaying text that contains '\n' characters.
+ *
+ */
+void
+nautilus_label_set_line_offset (NautilusLabel *label,
+ guint line_offset)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+
+ if (label->detail->line_offset == line_offset) {
+ return;
+ }
+
+ label->detail->line_offset = line_offset;
+
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+}
+
+/**
+ * nautilus_label_get_line_offset:
+ *
+ * @label: A NautilusLabel
+ *
+ * Return value: The line offset in pixels.
+ */
+guint
+nautilus_label_get_line_offset (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->line_offset;
+}
diff --git a/libnautilus-extensions/nautilus-label.h b/libnautilus-extensions/nautilus-label.h
new file mode 100644
index 000000000..58b76ed39
--- /dev/null
+++ b/libnautilus-extensions/nautilus-label.h
@@ -0,0 +1,102 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-label.h - A widget to display a anti aliased text.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+/* NautilusLabel is a widget that is capable of display anti aliased
+ * text composited over a complex background. The background can be
+ * installed as NautilusBackground on a NautilusLabel widget or any
+ * of its ancestors. The best background will automatically be found
+ * and used by the widget.
+ *
+ * Fonts can be specified using a NautilusScalableFont object.
+ *
+ * Text can contain embedded new lines.
+ *
+ */
+
+#ifndef NAUTILUS_LABEL_H
+#define NAUTILUS_LABEL_H
+
+#include <libnautilus-extensions/nautilus-buffered-widget.h>
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+
+/* NautilusLabel is GtkWidget that draws a string using the high quality
+ * anti aliased librsvg/freetype.
+ */
+
+BEGIN_GNOME_DECLS
+
+#define NAUTILUS_TYPE_LABEL (nautilus_label_get_type ())
+#define NAUTILUS_LABEL(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_LABEL, NautilusLabel))
+#define NAUTILUS_LABEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_LABEL, NautilusLabelClass))
+#define NAUTILUS_IS_LABEL(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_LABEL))
+#define NAUTILUS_IS_LABEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_LABEL))
+
+typedef struct _NautilusLabel NautilusLabel;
+typedef struct _NautilusLabelClass NautilusLabelClass;
+typedef struct _NautilusLabelDetail NautilusLabelDetail;
+
+struct _NautilusLabel
+{
+ /* Superclass */
+ NautilusBufferedWidget buffered_widget;
+
+ /* Private things */
+ NautilusLabelDetail *detail;
+};
+
+struct _NautilusLabelClass
+{
+ NautilusBufferedWidgetClass parent_class;
+};
+
+GtkType nautilus_label_get_type (void);
+GtkWidget * nautilus_label_new (void);
+void nautilus_label_set_text (NautilusLabel *label,
+ const char *text);
+char* nautilus_label_get_text (NautilusLabel *label);
+void nautilus_label_set_font (NautilusLabel *label,
+ NautilusScalableFont *font);
+NautilusScalableFont *nautilus_label_get_font (const NautilusLabel *label);
+void nautilus_label_set_font_size (NautilusLabel *label,
+ guint font_size);
+guint nautilus_label_get_font_size (const NautilusLabel *label);
+void nautilus_label_set_text_color (NautilusLabel *label,
+ guint32 color);
+guint32 nautilus_label_get_text_color (const NautilusLabel *label);
+void nautilus_label_set_text_alpha (NautilusLabel *label,
+ guchar alpha);
+guchar nautilus_label_get_text_alpha (const NautilusLabel *label);
+void nautilus_label_set_text_justification (NautilusLabel *label,
+ GtkJustification justification);
+GtkJustification nautilus_label_get_text_justification (const NautilusLabel *label);
+void nautilus_label_set_line_offset (NautilusLabel *label,
+ guint alpha);
+guint nautilus_label_get_line_offset (const NautilusLabel *label);
+
+
+END_GNOME_DECLS
+
+#endif /* NAUTILUS_LABEL_H */
+
+
diff --git a/libnautilus-extensions/nautilus-lib-self-check-functions.h b/libnautilus-extensions/nautilus-lib-self-check-functions.h
index cadc71e70..9a6c6a584 100644
--- a/libnautilus-extensions/nautilus-lib-self-check-functions.h
+++ b/libnautilus-extensions/nautilus-lib-self-check-functions.h
@@ -41,10 +41,11 @@ void nautilus_run_lib_self_checks (void);
#define NAUTILUS_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \
macro (nautilus_self_check_string) \
macro (nautilus_self_check_string_list) \
+ macro (nautilus_self_check_string_map) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_gdk_extensions) \
- macro (nautilus_self_check_search_uri) \
- macro (nautilus_self_check_file_utilities) \
+ macro (nautilus_self_check_search_uri) \
+ macro (nautilus_self_check_file_utilities) \
macro (nautilus_self_check_background) \
macro (nautilus_self_check_directory) \
macro (nautilus_self_check_file) \
diff --git a/libnautilus-extensions/nautilus-scalable-font.c b/libnautilus-extensions/nautilus-scalable-font.c
new file mode 100644
index 000000000..b6128fd05
--- /dev/null
+++ b/libnautilus-extensions/nautilus-scalable-font.c
@@ -0,0 +1,1056 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-scalable-font.c - A GtkObject subclass for access to scalable fonts.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+#include "nautilus-scalable-font.h"
+
+#include "nautilus-gtk-macros.h"
+#include "nautilus-gdk-extensions.h"
+#include "nautilus-gdk-pixbuf-extensions.h"
+#include "nautilus-background.h"
+#include "nautilus-string.h"
+#include "nautilus-file-utilities.h"
+#include "nautilus-glib-extensions.h"
+
+#include <librsvg/rsvg-ft.h>
+
+#include <libart_lgpl/art_misc.h>
+#include <libart_lgpl/art_alphagamma.h>
+#include <libart_lgpl/art_affine.h>
+#include <librsvg/art_render.h>
+#include <librsvg/art_render_mask.h>
+
+#include <stdio.h>
+#include <libgnome/gnome-util.h>
+#include <ctype.h>
+
+/* FontEntry */
+typedef struct {
+ char *weight;
+ char *slant;
+ char *set_width;
+ RsvgFTFontHandle font_handle;
+ char *path;
+} FontEntry;
+
+/* FontFamilyEntry */
+typedef struct {
+ char *family;
+ GList *fonts;
+} FontFamilyEntry;
+
+
+/* Detail member struct */
+struct _NautilusScalableFontDetail
+{
+ RsvgFTFontHandle font_handle;
+};
+
+/* Global things */
+static GHashTable *global_font_family_table = NULL;
+static RsvgFTCtx *global_rsvg_ft_context = NULL;
+static NautilusScalableFont *global_default_font = NULL;
+
+static const RsvgFTFontHandle UNDEFINED_FONT_HANDLE = -1;
+
+/* GtkObjectClass methods */
+static void nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class);
+static void nautilus_scalable_font_initialize (NautilusScalableFont *font);
+static void nautilus_scalable_font_destroy (GtkObject *object);
+static void initialize_global_stuff_if_needed (void);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusScalableFont, nautilus_scalable_font, GTK_TYPE_OBJECT)
+
+/* Class init methods */
+static void
+nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class)
+{
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (font_class);
+
+ initialize_global_stuff_if_needed ();
+
+ /* GtkObjectClass */
+ object_class->destroy = nautilus_scalable_font_destroy;
+}
+
+void
+nautilus_scalable_font_initialize (NautilusScalableFont *font)
+{
+ font->detail = g_new (NautilusScalableFontDetail, 1);
+
+ font->detail->font_handle = UNDEFINED_FONT_HANDLE;
+}
+
+/* GtkObjectClass methods */
+static void
+nautilus_scalable_font_destroy (GtkObject *object)
+{
+ NautilusScalableFont *font;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (object));
+
+ font = NAUTILUS_SCALABLE_FONT (object);
+
+ g_free (font->detail);
+
+ /* Chain destroy */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static char *
+file_as_string (const char *file_name)
+{
+ struct stat stat_info;
+ FILE *stream;
+ char *result;
+ size_t num_read;
+
+ g_return_val_if_fail (file_name != NULL, NULL);
+ g_return_val_if_fail (g_file_exists (file_name), NULL);
+
+ if (stat (file_name, &stat_info) != 0) {
+ return NULL;
+ }
+
+ if (stat_info.st_size == 0) {
+ return NULL;
+ }
+
+ stream = fopen (file_name, "r");
+
+ if (!stream) {
+ return NULL;
+ }
+
+ result = g_malloc (sizeof (char) * stat_info.st_size + 1);
+
+ num_read = fread (result, sizeof (char), stat_info.st_size, stream);
+
+ fclose (stream);
+
+ if (num_read != stat_info.st_size) {
+ g_free (result);
+ return NULL;
+ }
+
+ result[stat_info.st_size] = '\0';
+
+ return result;
+}
+
+static gboolean
+parse_font_description_file (const char *directory,
+ NautilusStringList **font_pfb_list_out,
+ NautilusStringList **font_xfld_list_out)
+{
+ char *fonts_dir_path;
+ char *fonts_dir_content;
+ NautilusStringList *tokenized_list;
+ guint i;
+ gint count;
+
+ g_return_val_if_fail (directory != NULL, FALSE);
+ g_return_val_if_fail (g_file_exists (directory), FALSE);
+ g_return_val_if_fail (font_pfb_list_out != NULL, FALSE);
+ g_return_val_if_fail (font_xfld_list_out != NULL, FALSE);
+
+ *font_pfb_list_out = NULL;
+ *font_xfld_list_out = NULL;
+
+ fonts_dir_path = g_strdup_printf ("%s/%s", directory, "fonts.dir");
+ fonts_dir_content = file_as_string (fonts_dir_path);
+ g_free (fonts_dir_path);
+
+ if (fonts_dir_content == NULL) {
+ return FALSE;
+ }
+
+ tokenized_list = nautilus_string_list_new_from_tokens (fonts_dir_content, "\n");
+ g_free (fonts_dir_content);
+
+ if (tokenized_list == NULL) {
+ return FALSE;
+ }
+
+ if (nautilus_string_list_get_length (tokenized_list) <= 1) {
+ nautilus_string_list_free (tokenized_list);
+ return FALSE;
+ }
+
+ if (!nautilus_eat_str_to_int (nautilus_string_list_nth (tokenized_list, 0), &count)) {
+ return FALSE;
+ }
+
+ *font_pfb_list_out = nautilus_string_list_new ();
+ *font_xfld_list_out = nautilus_string_list_new ();
+
+ for (i = 0; i < count; i++) {
+ char *line = nautilus_string_list_nth (tokenized_list, i + 1);
+
+ if (line != NULL) {
+ char *delimeter;
+
+ /* Look for the delimiting space */
+ delimeter = strstr (line, " ");
+ if (delimeter != NULL) {
+
+ char *font_pfb;
+ char *font_pfb_path;
+ guint pfb_length;
+
+ pfb_length = delimeter - line;
+ font_pfb = g_malloc (sizeof (char) * pfb_length + 1);
+ strncpy (font_pfb, line, pfb_length);
+ font_pfb[pfb_length] = '\0';
+
+ font_pfb_path = g_strdup_printf ("%s/%s", directory, font_pfb);
+
+ /* Make sure the pfb file exists */
+ if (g_file_exists (font_pfb_path)) {
+ while (isspace (*delimeter)) {
+ delimeter++;
+ }
+
+ nautilus_string_list_insert (*font_pfb_list_out, font_pfb_path);
+ nautilus_string_list_insert (*font_xfld_list_out, delimeter);
+ }
+
+ g_free (font_pfb);
+ g_free (font_pfb_path);
+ }
+
+ g_free (line);
+ }
+ }
+
+ nautilus_string_list_free (tokenized_list);
+
+ return TRUE;
+}
+
+/*
+ * FontEntry things
+ */
+static FontEntry*
+font_entry_new (const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *path)
+{
+ FontEntry *entry;
+
+ g_return_val_if_fail (weight != NULL, NULL);
+ g_return_val_if_fail (slant != NULL, NULL);
+ g_return_val_if_fail (set_width != NULL, NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+
+ entry = g_new (FontEntry, 1);
+
+ entry->weight = g_strdup (weight);
+ entry->slant = g_strdup (slant);
+ entry->set_width = g_strdup (set_width);
+ entry->path = g_strdup (path);
+ entry->font_handle = UNDEFINED_FONT_HANDLE;
+
+ return entry;
+}
+
+static void
+font_entry_free (FontEntry* entry)
+{
+ g_return_if_fail (entry != NULL);
+
+ g_free (entry->weight);
+ g_free (entry->slant);
+ g_free (entry->set_width);
+ g_free (entry->path);
+
+ /* These fonts arent refcounted because they are catched internally by librsvg */
+ entry->font_handle = UNDEFINED_FONT_HANDLE;
+
+ g_free (entry);
+}
+
+/*
+ * FontFamilyEntry things
+ */
+static FontFamilyEntry*
+font_family_new (const char *family)
+{
+ FontFamilyEntry *entry;
+
+ g_return_val_if_fail (family != NULL, NULL);
+
+ entry = g_new (FontFamilyEntry, 1);
+
+ entry->family = g_strdup (family);
+ entry->fonts = NULL;
+
+ return entry;
+}
+
+static void
+free_font_entry (gpointer data, gpointer user_data)
+{
+ font_entry_free ((FontEntry*) data);
+}
+
+static void
+font_family_free (FontFamilyEntry* entry)
+{
+ g_return_if_fail (entry != NULL);
+
+ g_free (entry->family);
+
+ nautilus_g_list_free_deep_custom (entry->fonts, free_font_entry, NULL);
+ entry->fonts = NULL;
+
+ g_free (entry);
+}
+
+static void
+font_family_insert_font (FontFamilyEntry *family_entry, FontEntry *font_entry)
+{
+ g_return_if_fail (family_entry != NULL);
+ g_return_if_fail (font_entry != NULL);
+
+ family_entry->fonts = g_list_append (family_entry->fonts, (gpointer) font_entry);
+}
+
+#define EQUAL 0
+#define NOT_EQUAL 1
+
+static gint
+font_compare (gconstpointer a, gconstpointer b)
+{
+ FontEntry *font_entry_a = (FontEntry *) a;
+ FontEntry *font_entry_b = (FontEntry *) b;
+
+ g_return_val_if_fail (font_entry_a != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_b != NULL, NOT_EQUAL);
+
+ g_return_val_if_fail (font_entry_a->weight != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_a->slant != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_a->set_width != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_b->weight != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_b->slant != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_b->set_width != NULL, NOT_EQUAL);
+
+ return (nautilus_str_is_equal (font_entry_a->weight, font_entry_b->weight)
+ && nautilus_str_is_equal (font_entry_a->slant, font_entry_b->slant)
+ && nautilus_str_is_equal (font_entry_a->set_width, font_entry_b->set_width)) ? EQUAL : NOT_EQUAL;
+}
+
+static FontEntry*
+font_family_find_font (const FontFamilyEntry *family_entry,
+ const char *weight,
+ const char *slant,
+ const char *set_width)
+{
+ FontEntry fake_font_entry;
+
+ GList *node;
+
+ g_return_val_if_fail (family_entry != NULL, NULL);
+ g_return_val_if_fail (weight != NULL, NULL);
+ g_return_val_if_fail (slant != NULL, NULL);
+ g_return_val_if_fail (set_width != NULL, NULL);
+
+ fake_font_entry.weight = (char *) weight;
+ fake_font_entry.slant = (char *) slant;
+ fake_font_entry.set_width = (char *) set_width;
+
+ node = g_list_find_custom (family_entry->fonts, &fake_font_entry, font_compare);
+
+ return node ? node->data : NULL;
+}
+
+static FontFamilyEntry *
+font_family_lookup (GHashTable *font_family_table, const char *family)
+{
+ gpointer value;
+
+ g_return_val_if_fail (font_family_table != NULL, NULL);
+ g_return_val_if_fail (family != NULL, NULL);
+
+ value = g_hash_table_lookup (font_family_table, (gconstpointer) family);
+
+ return (FontFamilyEntry *) value;
+}
+
+static FontFamilyEntry *
+font_family_lookup_with_insertion (GHashTable *font_family_table, const char *family)
+{
+ FontFamilyEntry *entry;
+
+ g_return_val_if_fail (font_family_table != NULL, NULL);
+ g_return_val_if_fail (family != NULL, NULL);
+
+ entry = g_hash_table_lookup (font_family_table, (gconstpointer) family);
+
+ if (entry == NULL) {
+
+ entry = font_family_new (family);
+
+ g_hash_table_insert (font_family_table, entry->family, entry);
+ }
+
+ return entry;
+}
+
+static void
+font_family_table_add_fonts (GHashTable *font_family_table, const char *font_path)
+{
+ NautilusStringList *font_pfb_list = NULL;
+ NautilusStringList *font_xfld_list = NULL;
+ guint i;
+
+ g_return_if_fail (font_family_table != NULL);
+ g_return_if_fail (font_path != NULL);
+ g_return_if_fail (g_file_exists (font_path));
+
+ if (!parse_font_description_file (font_path, &font_pfb_list, &font_xfld_list)) {
+ g_warning ("Dude, could not find no stikin fonts in %s", font_path);
+ return;
+ }
+
+ if (nautilus_string_list_get_length (font_pfb_list) != nautilus_string_list_get_length (font_xfld_list)) {
+ g_warning ("Dude, something got fucked");
+ return;
+ }
+
+ for (i = 0; i < nautilus_string_list_get_length (font_pfb_list); i++) {
+ NautilusStringList *tokenized_xfld;
+ char *path;
+ char *xfld;
+
+ char *foundry;
+ char *family;
+ char *weight;
+ char *slant;
+ char *set_width;
+
+ FontFamilyEntry *family_entry;
+ FontEntry *font_entry;
+
+ path = nautilus_string_list_nth (font_pfb_list, i);
+ g_assert (path != NULL);
+
+ xfld = nautilus_string_list_nth (font_xfld_list, i);
+ g_assert (xfld != NULL);
+
+ tokenized_xfld = nautilus_string_list_new_from_tokens (xfld, "-");
+
+ foundry = nautilus_string_list_nth (tokenized_xfld, 1);
+ family = nautilus_string_list_nth (tokenized_xfld, 2);
+ weight = nautilus_string_list_nth (tokenized_xfld, 3);
+ slant = nautilus_string_list_nth (tokenized_xfld, 4);
+ set_width = nautilus_string_list_nth (tokenized_xfld, 5);
+
+ family_entry = font_family_lookup_with_insertion (font_family_table, family);
+ g_assert (family_entry != NULL);
+
+ font_entry = font_family_find_font (family_entry, weight, slant, set_width);
+
+ if (font_entry != NULL) {
+ g_warning ("Dude, the font '%s-%s-%s-%s' already exists", family, weight, slant, set_width);
+ }
+ else {
+ font_entry = font_entry_new (weight, slant, set_width, path);
+
+ font_family_insert_font (family_entry, font_entry);
+ }
+
+ nautilus_string_list_free (tokenized_xfld);
+ g_free (foundry);
+ g_free (family);
+ g_free (weight);
+ g_free (slant);
+ g_free (set_width);
+
+ g_free (path);
+ g_free (xfld);
+ }
+
+ nautilus_string_list_free (font_pfb_list);
+ nautilus_string_list_free (font_xfld_list);
+}
+
+/* Public NautilusScalableFont methods */
+GtkObject*
+nautilus_scalable_font_new (const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width)
+{
+ /* const char *foundry = "URW"; */
+ FontFamilyEntry *family_entry;
+ FontEntry *font_entry;
+ NautilusScalableFont *font;
+
+ initialize_global_stuff_if_needed ();
+
+ family_entry = font_family_lookup (global_font_family_table, family);
+
+ if (family_entry == NULL) {
+ g_warning ("There is no such font: %s", family);
+ return NULL;
+ }
+
+ weight = weight ? weight : "medium";
+ slant = slant ? slant : "r";
+ set_width = set_width ? set_width : "normal";
+
+ font_entry = font_family_find_font (family_entry, weight, slant, set_width);
+
+ if (font_entry == NULL) {
+ g_warning ("There is no such font '%s-%s-%s-%s'", family, weight, slant, set_width);
+ return NULL;
+ }
+
+ /* 'Intern' the rsvg font handle if needed */
+ if (font_entry->font_handle == UNDEFINED_FONT_HANDLE) {
+ font_entry->font_handle = rsvg_ft_intern (global_rsvg_ft_context, font_entry->path);
+
+ }
+
+#if 0
+ g_print ("%s (%s, %s, %s %s) handle = %d\n" ,
+ __FUNCTION__, family, weight, slant, set_width, font_entry->font_handle);
+#endif
+
+ font = NAUTILUS_SCALABLE_FONT (gtk_type_new (nautilus_scalable_font_get_type ()));
+
+ font->detail->font_handle = font_entry->font_handle;
+
+ return GTK_OBJECT (font);
+}
+
+void
+nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text,
+ guint *text_width_out,
+ guint *text_height_out)
+{
+ RsvgFTGlyph *glyph;
+ double affine[6];
+ int glyph_xy[2];
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (text_width_out != NULL);
+ g_return_if_fail (text_height_out != NULL);
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+
+ *text_width_out = 0;
+ *text_height_out = 0;
+
+ if (text == NULL) {
+ return;
+ }
+
+ art_affine_identity (affine);
+
+ /* FIXME: We need to change rsvg_ft_render_string() to accept
+ * a 'do_render' flag so that we can use to to compute metrics
+ * without actually having to render
+ */
+ glyph = rsvg_ft_render_string (global_rsvg_ft_context,
+ font->detail->font_handle,
+ text,
+ font_width,
+ font_height,
+ affine,
+ glyph_xy);
+
+ *text_width_out = glyph->width;
+ *text_height_out = glyph->height;
+
+ rsvg_ft_glyph_unref (glyph);
+}
+
+void
+nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ guint num_text_lines,
+ guint text_line_widths[],
+ guint text_line_heights[],
+ guint *max_width_out,
+ guint *total_height_out)
+{
+ guint i;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text_lines != NULL);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (num_text_lines > 0);
+
+ if (max_width_out != NULL) {
+ *max_width_out = 0;
+ }
+
+ if (total_height_out != NULL) {
+ *total_height_out = 0;
+ }
+
+ for (i = 0; i < num_text_lines; i++) {
+ g_assert (text_lines[i] != NULL);
+ g_assert (text_line_widths[i] > 0);
+ g_assert (text_line_heights[i] > 0);
+
+ nautilus_scalable_font_measure_text (font,
+ font_width,
+ font_height,
+ text_lines[i],
+ &text_line_widths[i],
+ &text_line_heights[i]);
+
+ if (total_height_out != NULL) {
+ *total_height_out += text_line_heights[i];
+ }
+
+ if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) {
+ *max_width_out = text_line_widths[i];
+ }
+ }
+}
+
+guint
+nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,
+ const char *text,
+ guint available_width,
+ const guint font_sizes[],
+ guint num_font_sizes)
+{
+ NautilusStringList *tokenized_string;
+ guint i;
+ char *longest_string;
+
+ g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0);
+ g_return_val_if_fail (font_sizes != NULL, 0);
+ g_return_val_if_fail (num_font_sizes > 0, 0);
+
+ if (text == NULL || available_width < 1) {
+ return font_sizes[num_font_sizes - 1];
+ }
+
+ tokenized_string = nautilus_string_list_new_from_tokens (text, "\n");
+ longest_string = nautilus_string_list_get_longest_string (tokenized_string);
+ g_assert (longest_string != NULL);
+ nautilus_string_list_free (tokenized_string);
+
+ for (i = 0; i < num_font_sizes; i++) {
+ guint text_width;
+ guint text_height;
+
+ nautilus_scalable_font_measure_text (font,
+ font_sizes[i],
+ font_sizes[i],
+ longest_string,
+ &text_width,
+ &text_height);
+
+ if (text_width <= available_width) {
+ g_free (longest_string);
+ return font_sizes[i];
+ }
+ }
+
+ g_free (longest_string);
+
+ return font_sizes[num_font_sizes - 1];
+}
+
+void
+nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_area,
+ guint font_width,
+ guint font_height,
+ const char *text,
+ guint32 color,
+ guchar overall_alpha)
+{
+ RsvgFTGlyph *glyph;
+ double affine[6];
+ int glyph_xy[2];
+
+ guint pixbuf_width;
+ guint pixbuf_height;
+ guint pixbuf_rowstride;
+ guchar *pixbuf_pixels;
+
+ ArtRender *art_render;
+ ArtPixMaxDepth art_color_array[3];
+
+ ArtIRect area;
+ ArtIRect glyph_area;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (destination_pixbuf != NULL);
+ g_return_if_fail (destination_area != NULL);
+ g_return_if_fail (destination_area->x1 > destination_area->x0);
+ g_return_if_fail (destination_area->y1 > destination_area->y0);
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+
+ if (text == NULL) {
+ return;
+ }
+
+ art_affine_identity (affine);
+
+ glyph = rsvg_ft_render_string (global_rsvg_ft_context,
+ font->detail->font_handle,
+ text,
+ font_width,
+ font_height,
+ affine,
+ glyph_xy);
+
+ pixbuf_width = gdk_pixbuf_get_width (destination_pixbuf);
+ pixbuf_height = gdk_pixbuf_get_height (destination_pixbuf);
+ pixbuf_rowstride = gdk_pixbuf_get_rowstride (destination_pixbuf);
+ pixbuf_pixels = gdk_pixbuf_get_pixels (destination_pixbuf);
+
+ glyph_xy[0] = 0;
+ glyph_xy[1] = 0;
+
+ art_render = art_render_new (0,
+ 0,
+ pixbuf_width,
+ pixbuf_height,
+ pixbuf_pixels,
+ pixbuf_rowstride,
+ 3,
+ 8,
+ ART_ALPHA_SEPARATE,
+ NULL);
+
+ art_color_array[0] = ART_PIX_MAX_FROM_8 (NAUTILUS_RGBA_COLOR_GET_R (color));
+ art_color_array[1] = ART_PIX_MAX_FROM_8 (NAUTILUS_RGBA_COLOR_GET_G (color));
+ art_color_array[2] = ART_PIX_MAX_FROM_8 (NAUTILUS_RGBA_COLOR_GET_B (color));
+
+ art_render_image_solid (art_render, art_color_array);
+
+ glyph_area.x0 = glyph_xy[0] + destination_area->x0;
+ glyph_area.y0 = glyph_xy[1] + destination_area->y0;
+
+ glyph_area.x1 = glyph_area.x0 + glyph->width;
+ glyph_area.y1 = glyph_area.y0 + glyph->height;
+
+ art_irect_union (&area, &glyph_area, destination_area);
+
+/* glyph_xy[0] += destination_point->x; */
+/* glyph_xy[1] += destination_point->y; */
+
+ art_render_mask (art_render,
+ glyph_area.x0,
+ glyph_area.y0,
+ glyph_area.x1,
+ glyph_area.y1,
+ glyph->buf,
+ glyph->rowstride);
+
+ art_render_invoke (art_render);
+
+ rsvg_ft_glyph_unref (glyph);
+}
+
+void
+nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_area,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ const guint text_line_widths[],
+ const guint text_line_heights[],
+ GtkJustification justification,
+ const guint num_text_lines,
+ guint line_offset,
+ guint32 color,
+ guchar overall_alpha)
+{
+ guint i;
+
+ gint x;
+ gint y;
+
+ guint available_width;
+ guint available_height;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (destination_pixbuf != NULL);
+ g_return_if_fail (destination_area != NULL);
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text_lines != NULL);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (num_text_lines > 0);
+ g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL);
+ g_return_if_fail (destination_area->x1 > destination_area->x0);
+ g_return_if_fail (destination_area->y1 > destination_area->y0);
+
+ x = destination_area->x0;
+ y = destination_area->y0;
+
+ available_width = destination_area->x1 - destination_area->x0;
+ available_height = destination_area->y1 - destination_area->y0;
+
+ for (i = 0; i < num_text_lines; i++) {
+ ArtIRect area;
+
+ g_assert (text_lines[i] != NULL);
+ g_assert (text_line_widths[i] > 0);
+ g_assert (text_line_heights[i] > 0);
+
+ switch (justification) {
+ case GTK_JUSTIFY_LEFT:
+ area.x0 = x;
+ break;
+
+ case GTK_JUSTIFY_CENTER:
+ case GTK_JUSTIFY_FILL:
+ if (text_line_widths[i] <= available_width) {
+ area.x0 = x + ((available_width - text_line_widths[i]) / 2);
+ }
+ else {
+ area.x0 = x - ((text_line_widths[i] - available_width) / 2);
+ }
+ break;
+
+ case GTK_JUSTIFY_RIGHT:
+ area.x0 = x + available_width - text_line_widths[i];
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ area.y0 = y;
+
+ nautilus_scalable_font_draw_text (font,
+ destination_pixbuf,
+ &area,
+ font_width,
+ font_height,
+ text_lines[i],
+ color,
+ overall_alpha);
+
+ y += (line_offset + text_line_heights[i]);
+ }
+}
+
+static void
+default_font_at_exit_destructor (void)
+{
+ if (global_default_font != NULL) {
+ gtk_object_unref (GTK_OBJECT (global_default_font));
+ global_default_font = NULL;
+ }
+}
+
+NautilusScalableFont *
+nautilus_scalable_font_get_default_font (void)
+{
+ if (global_default_font == NULL) {
+ global_default_font = NAUTILUS_SCALABLE_FONT (nautilus_scalable_font_new ("Nimbus Sans L", NULL, NULL, NULL));
+ g_assert (global_default_font != NULL);
+ g_atexit (default_font_at_exit_destructor);
+ }
+
+ gtk_object_ref (GTK_OBJECT (global_default_font));
+
+ return global_default_font;
+}
+
+static void
+font_family_table_for_each_append (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ NautilusStringList *list = (NautilusStringList *) user_data;
+ FontFamilyEntry *family_entry = (FontFamilyEntry *) value;
+
+ g_assert (family_entry != NULL);
+ g_assert (!nautilus_string_list_contains (list, family_entry->family));
+
+ nautilus_string_list_insert (list, family_entry->family);
+}
+
+static void
+font_family_table_for_each_free (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ FontFamilyEntry *family_entry = (FontFamilyEntry *) value;
+ g_assert (family_entry != NULL);
+
+ font_family_free (family_entry);
+}
+
+static NautilusStringList *
+font_family_table_get_family_list (GHashTable *font_family_table)
+{
+ NautilusStringList *list;
+
+ g_return_val_if_fail (font_family_table != NULL, NULL);
+
+ list = nautilus_string_list_new ();
+
+ g_hash_table_foreach (font_family_table, font_family_table_for_each_append, list);
+
+ return list;
+}
+
+NautilusStringList *
+nautilus_scalable_font_get_font_family_list (void)
+{
+ initialize_global_stuff_if_needed ();
+
+ return font_family_table_get_family_list (global_font_family_table);
+}
+
+static void
+font_family_table_free (GHashTable *font_family_table)
+{
+ g_assert (font_family_table != NULL);
+
+ g_hash_table_foreach (font_family_table, font_family_table_for_each_free, NULL);
+
+ g_hash_table_destroy (font_family_table);
+}
+
+static void
+font_family_table_at_exit_destructor (void)
+{
+ if (global_font_family_table != NULL) {
+ font_family_table_free (global_font_family_table);
+ global_font_family_table = NULL;
+ }
+}
+
+gboolean
+nautilus_scalable_font_query_font (const char *family,
+ NautilusStringList **weights_out,
+ NautilusStringList **slants_out,
+ NautilusStringList **set_widths_out)
+{
+ FontFamilyEntry *family_entry;
+ GList *iterator;
+
+ g_return_val_if_fail (family != NULL, FALSE);
+
+ if (weights_out != NULL) {
+ *weights_out = NULL;
+ }
+
+ if (slants_out != NULL) {
+ *slants_out = NULL;
+ }
+
+ if (set_widths_out != NULL) {
+ *set_widths_out = NULL;
+ }
+
+ family_entry = font_family_lookup (global_font_family_table, family);
+
+ if (family_entry == NULL) {
+ return FALSE;
+ }
+
+ if (weights_out == NULL && slants_out == NULL && set_widths_out == NULL) {
+ return TRUE;
+ }
+
+ if (weights_out != NULL) {
+ *weights_out = nautilus_string_list_new ();
+ }
+
+ if (slants_out != NULL) {
+ *slants_out = nautilus_string_list_new ();
+ }
+
+ if (set_widths_out != NULL) {
+ *set_widths_out = nautilus_string_list_new ();
+ }
+
+ for (iterator = family_entry->fonts; iterator != NULL; iterator = iterator->next) {
+ FontEntry *font_entry = (FontEntry *) iterator->data;
+ g_assert (font_entry != NULL);
+
+ if (weights_out != NULL) {
+ nautilus_string_list_insert (*weights_out, font_entry->weight);
+ }
+
+ if (slants_out != NULL) {
+ nautilus_string_list_insert (*slants_out, font_entry->slant);
+ }
+
+ if (set_widths_out != NULL) {
+ nautilus_string_list_insert (*set_widths_out, font_entry->set_width);
+ }
+ }
+
+ return TRUE;
+}
+
+#if 0
+static const char * global_default_font_path[] =
+{
+ "/usr/lib/X11/fonts/Type1",
+ "/usr/share/fonts/default/Type1"
+};
+#endif
+
+static void
+initialize_global_stuff_if_needed (void)
+{
+ static gboolean fonts_initialized = FALSE;
+
+ /* Initialize the rsvg font context shared by all fonts */
+ if (global_rsvg_ft_context == NULL) {
+ global_rsvg_ft_context = rsvg_ft_ctx_new ();
+ }
+
+ /* Initialize the global font table */
+ if (fonts_initialized == FALSE) {
+ fonts_initialized = TRUE;
+ global_font_family_table = g_hash_table_new (g_str_hash, g_str_equal);
+ font_family_table_add_fonts (global_font_family_table, "/usr/share/fonts/default/Type1");
+
+ g_atexit (font_family_table_at_exit_destructor);
+ }
+}
diff --git a/libnautilus-extensions/nautilus-scalable-font.h b/libnautilus-extensions/nautilus-scalable-font.h
new file mode 100644
index 000000000..f640e9b45
--- /dev/null
+++ b/libnautilus-extensions/nautilus-scalable-font.h
@@ -0,0 +1,138 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-scalable-font.h - A GtkObject subclass for access to scalable fonts.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+
+/* NautilusScalableFont is a GtkObject that provdes a simple
+ * interface to Raph Levien's librsvg FreeType2 bases anti aliased
+ * text rendering.
+ *
+ * Currently, Type1 only Type1 fonts are supported.
+ *
+ * Fonts are automatically queried and used if available. Right
+ * now this is fairly simple code which does not handle all the
+ * complexities of the hell that is x fonts.
+ *
+ * In the Star Trek future, we will use gnome-print (gnome-font?).
+ * However, we will keep the interface to scalable font usage simple
+ * and hidden behind this interface.
+ *
+ */
+
+#ifndef NAUTILUS_SCALABLE_FONT_H
+#define NAUTILUS_SCALABLE_FONT_H
+
+#include <gtk/gtkobject.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <libgnome/gnome-defs.h>
+#include <libnautilus-extensions/nautilus-string-list.h>
+#include <libart_lgpl/art_rect.h>
+
+BEGIN_GNOME_DECLS
+
+#define NAUTILUS_TYPE_SCALABLE_FONT (nautilus_scalable_font_get_type ())
+#define NAUTILUS_SCALABLE_FONT(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_SCALABLE_FONT, NautilusScalableFont))
+#define NAUTILUS_SCALABLE_FONT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_SCALABLE_FONT, NautilusScalableFontClass))
+#define NAUTILUS_IS_SCALABLE_FONT(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_SCALABLE_FONT))
+#define NAUTILUS_IS_SCALABLE_FONT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_SCALABLE_FONT))
+
+typedef struct _NautilusScalableFont NautilusScalableFont;
+typedef struct _NautilusScalableFontClass NautilusScalableFontClass;
+typedef struct _NautilusScalableFontDetail NautilusScalableFontDetail;
+
+struct _NautilusScalableFont
+{
+ /* Superclass */
+ GtkObject object;
+
+ /* Private things */
+ NautilusScalableFontDetail *detail;
+};
+
+struct _NautilusScalableFontClass
+{
+ GtkObjectClass parent_class;
+};
+
+GtkType nautilus_scalable_font_get_type (void);
+GtkObject * nautilus_scalable_font_new (const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width);
+void nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text,
+ guint *text_width_out,
+ guint *text_height_out);
+void nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ guint num_text_lines,
+ guint text_line_widths[],
+ guint text_line_heights[],
+ guint *max_width_out,
+ guint *total_height_out);
+void nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_area,
+ guint font_width,
+ guint font_height,
+ const char *text,
+ guint32 color,
+ guchar overall_alpha);
+void nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_area,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ const guint text_line_widths[],
+ const guint text_line_heights[],
+ GtkJustification justification,
+ const guint num_lines,
+ guint line_offset,
+ guint32 color,
+ guchar overall_alpha);
+guint nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,
+ const char *text,
+ guint available_width,
+ const guint font_sizes[],
+ guint num_font_sizes);
+NautilusScalableFont *nautilus_scalable_font_get_default_font (void);
+NautilusStringList * nautilus_scalable_font_get_font_family_list (void);
+gboolean nautilus_scalable_font_query_font (const char *family,
+ NautilusStringList **weights,
+ NautilusStringList **slants,
+ NautilusStringList **set_widths);
+gboolean nautilus_scalable_font_query_font (const char *family,
+ NautilusStringList **weights,
+ NautilusStringList **slants,
+ NautilusStringList **set_widths);
+
+END_GNOME_DECLS
+
+#endif /* NAUTILUS_SCALABLE_FONT_H */
+
+
diff --git a/libnautilus-extensions/nautilus-string-map.c b/libnautilus-extensions/nautilus-string-map.c
new file mode 100644
index 000000000..e93c9b052
--- /dev/null
+++ b/libnautilus-extensions/nautilus-string-map.c
@@ -0,0 +1,295 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-string-list.h: A collection of strings.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+
+#include "nautilus-string-map.h"
+#include "nautilus-string-list.h"
+#include "nautilus-string.h"
+#include "nautilus-glib-extensions.h"
+#include "nautilus-lib-self-check-functions.h"
+#include <string.h>
+
+/* FIXME: The case sensitive flag is not functional yet. Need to change
+ * NautilusStringList to also accept a case_sensitive flag to make it work.
+ */
+
+struct _NautilusStringMap
+{
+ GList *map;
+ gboolean case_sensitive;
+};
+
+typedef struct
+{
+ char *string;
+ NautilusStringList *map_list;
+} MapEntry;
+
+/* MapEntry things */
+static MapEntry *map_entry_new (const char *string);
+static void map_entry_free (MapEntry *map_entry);
+static MapEntry *map_entry_list_lookup_mapped_string (GList *entry_list,
+ const char *mapped_string);
+static MapEntry *map_entry_list_lookup (GList *entry_list,
+ const char *string);
+
+/**
+ * nautilus_string_map_new:
+ *
+ * @case_sensitive: Boolean flag indicating whether the string map is case sensitive.
+ *
+ * Allocate an empty string map.
+ *
+ * Return value: A newly allocated string map.
+ */
+NautilusStringMap *
+nautilus_string_map_new (gboolean case_sensitive)
+{
+ NautilusStringMap * string_map;
+
+ string_map = g_new (NautilusStringMap, 1);
+
+ string_map->map = NULL;
+ string_map->case_sensitive = case_sensitive;
+
+ return string_map;
+}
+
+/**
+ * nautilus_string_map_free:
+ *
+ * @string_map: A NautilusStringMap
+ *
+ * Free the string map.
+ */
+void
+nautilus_string_map_free (NautilusStringMap *string_map)
+{
+ if (string_map == NULL) {
+ return;
+ }
+
+ nautilus_string_map_clear (string_map);
+
+ g_free (string_map);
+}
+
+static void
+map_for_each_node_free (gpointer data,
+ gpointer user_data)
+{
+ MapEntry *map_entry = (MapEntry *) data;
+ g_assert (map_entry != NULL);
+
+ map_entry_free (map_entry);
+}
+
+/**
+ * nautilus_string_map_clear:
+ *
+ * @string_map: A NautilusStringMap
+ *
+ * Clear the string map.
+ */
+void
+nautilus_string_map_clear (NautilusStringMap *string_map)
+{
+ if (string_map == NULL) {
+ return;
+ }
+
+ g_return_if_fail (string_map != NULL);
+
+ nautilus_g_list_free_deep_custom (string_map->map, map_for_each_node_free, NULL);
+
+ string_map->map = NULL;
+}
+
+/**
+ * nautilus_string_map_lookup:
+ *
+ * @string_map: A NautilusStringMap
+ * @string: The mapped string to lookup
+ *
+ * Lookup the mapping for 'string'
+ *
+ * Return value: A copy of the mapped_to_string or NULL if no mapping exists.
+ */
+char *
+nautilus_string_map_lookup (const NautilusStringMap *string_map,
+ const char *string)
+{
+ MapEntry *map_entry;
+
+ if (string_map == NULL || string == NULL) {
+ return NULL;
+ }
+
+ map_entry = map_entry_list_lookup (string_map->map, string);
+
+ return map_entry ? g_strdup (map_entry->string) : NULL;
+}
+
+/**
+ * nautilus_string_map_add:
+ *
+ * @string_map: A NautilusStringMap
+ *
+ * Add a mapping from 'string' to 'strings_maps_to'
+ */
+void
+nautilus_string_map_add (NautilusStringMap *string_map,
+ const char *string_maps_to,
+ const char *string)
+{
+ MapEntry *map_entry;
+
+ g_return_if_fail (string_map != NULL);
+ g_return_if_fail (string_maps_to != NULL);
+ g_return_if_fail (string != NULL);
+
+ map_entry = map_entry_list_lookup_mapped_string (string_map->map, string_maps_to);
+
+ if (map_entry == NULL) {
+ map_entry = map_entry_new (string_maps_to);
+
+ /* Add a mapping for the string_maps_to to simplify things */
+ nautilus_string_list_insert (map_entry->map_list, string_maps_to);
+
+ string_map->map = g_list_append (string_map->map, map_entry);
+ }
+
+ nautilus_string_list_insert (map_entry->map_list, string);
+}
+
+/* MapEntry things */
+static MapEntry *
+map_entry_new (const char *string)
+{
+ MapEntry *map_entry;
+
+ g_return_val_if_fail (string != NULL, NULL);
+
+ map_entry = g_new (MapEntry, 1);
+ map_entry->map_list = nautilus_string_list_new ();
+ map_entry->string = g_strdup (string);
+
+ return map_entry;
+}
+
+static void
+map_entry_free (MapEntry *map_entry)
+{
+ g_return_if_fail (map_entry);
+
+ nautilus_string_list_free (map_entry->map_list);
+ map_entry->map_list = NULL;
+ g_free (map_entry->string);
+ g_free (map_entry);
+}
+
+static MapEntry *
+map_entry_list_lookup_mapped_string (GList *entry_list,
+ const char *mapped_string)
+{
+ GList *iterator;
+
+ g_return_val_if_fail (mapped_string != NULL, NULL);
+
+ if (entry_list == NULL) {
+ return NULL;
+ }
+
+ for (iterator = entry_list; iterator != NULL; iterator = iterator->next) {
+ MapEntry *map_entry = (MapEntry *) iterator->data;
+ g_assert (map_entry != NULL);
+
+ if (nautilus_str_is_equal (map_entry->string, mapped_string)) {
+ return map_entry;
+ }
+ }
+
+ return NULL;
+}
+
+static MapEntry *
+map_entry_list_lookup (GList *entry_list,
+ const char *string)
+{
+ GList *iterator;
+
+ g_return_val_if_fail (string != NULL, NULL);
+
+ if (entry_list == NULL) {
+ return NULL;
+ }
+
+ for (iterator = entry_list; iterator != NULL; iterator = iterator->next) {
+ MapEntry *map_entry = (MapEntry *) iterator->data;
+ g_assert (map_entry != NULL);
+
+ if (nautilus_string_list_contains (map_entry->map_list, string)) {
+ return map_entry;
+ }
+ }
+
+ return NULL;
+}
+
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+
+void
+nautilus_self_check_string_map (void)
+{
+#if 0
+ NautilusStringMap *map;
+
+ map = nautilus_string_map_new (TRUE);
+
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "foo"), NULL);
+
+ nautilus_string_map_clear (map);
+
+ nautilus_string_map_add (map, "animal", "dog");
+ nautilus_string_map_add (map, "animal", "cat");
+ nautilus_string_map_add (map, "animal", "mouse");
+ nautilus_string_map_add (map, "human", "geek");
+ nautilus_string_map_add (map, "human", "nerd");
+ nautilus_string_map_add (map, "human", "lozer");
+
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "animal"), "animal");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "cat"), "animal");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "dog"), "animal");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "mouse"), "animal");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "human"), "human");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "geek"), "human");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "nerd"), "human");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "lozer"), "human");
+
+ nautilus_string_map_free (map);
+#endif
+}
+
+#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-extensions/nautilus-string-map.h b/libnautilus-extensions/nautilus-string-map.h
new file mode 100644
index 000000000..71b5820e9
--- /dev/null
+++ b/libnautilus-extensions/nautilus-string-map.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-string-list.h: A collection of strings.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#ifndef NAUTILUS_STRING_MAP_H
+#define NAUTILUS_STRING_MAP_H
+
+#include <glib.h>
+
+/* Opaque type declaration. */
+typedef struct _NautilusStringMap NautilusStringMap;
+
+/* Construct an empty string list. */
+NautilusStringMap *nautilus_string_map_new (gboolean case_sensitive);
+
+/* Construct a string list with a single element */
+void nautilus_string_map_add (NautilusStringMap *string_map,
+ const char *string_maps_to,
+ const char *string);
+void nautilus_string_map_free (NautilusStringMap *string_map);
+void nautilus_string_map_clear (NautilusStringMap *string_map);
+char * nautilus_string_map_lookup (const NautilusStringMap *string_map,
+ const char *key);
+
+#endif /* NAUTILUS_STRING_MAP_H */
+
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 91da8cd95..91732d5db 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -21,11 +21,15 @@ INCLUDES = \
-DNAUTILUS_DATADIR=\""$(datadir)/nautilus"\" \
$(NULL)
-libnautilus_extensions_la_LDFLAGS= \
+dependency_static_libs =\
$(top_builddir)/cut-n-paste-code/widgets/e-paned/libe-paned.la \
$(top_builddir)/cut-n-paste-code/widgets/nautilus-druid/libnautilus-druid.la \
$(top_builddir)/librsvg/librsvg.la \
$(top_builddir)/cut-n-paste-code/freetype/libfreetype2.la \
+ $(NULL)
+
+libnautilus_extensions_la_LDFLAGS= \
+ $(dependency_static_libs) \
$(GNOME_LIBS) \
$(GNOMECANVASPIXBUF_LIBS) \
$(OAF_LIBS) \
@@ -44,6 +48,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-background.c \
nautilus-bonobo-extensions.c \
nautilus-bookmark.c \
+ nautilus-buffered-widget.c \
nautilus-caption-table.c \
nautilus-caption.c \
nautilus-debug.c \
@@ -58,6 +63,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-file-utilities.c \
nautilus-file.c \
nautilus-font-factory.c \
+ nautilus-font-picker.c \
nautilus-gdk-extensions.c \
nautilus-gdk-pixbuf-extensions.c \
nautilus-generous-bin.c \
@@ -74,6 +80,7 @@ libnautilus_extensions_la_SOURCES = \
nautilus-icon-text-item.c \
nautilus-image.c \
nautilus-keep-last-vertical-box.c \
+ nautilus-label.c \
nautilus-lib-self-check-functions.c \
nautilus-link-set.c \
nautilus-link.c \
@@ -91,23 +98,25 @@ libnautilus_extensions_la_SOURCES = \
nautilus-program-chooser.c \
nautilus-program-choosing.c \
nautilus-radio-button-group.c \
+ nautilus-scalable-font.c \
nautilus-search-bar-criterion.c \
nautilus-search-uri.c \
nautilus-self-checks.c \
nautilus-stock-dialogs.c \
nautilus-string-list.c \
+ nautilus-string-map.c \
nautilus-string-picker.c \
nautilus-string.c \
nautilus-text-caption.c \
- nautilus-trash-directory.c \
nautilus-theme.c \
+ nautilus-trash-directory.c \
nautilus-undo-context.c \
nautilus-undo-manager.c \
nautilus-undo-signal-handlers.c \
nautilus-user-level-manager.c \
+ nautilus-vfs-directory.c \
nautilus-view-identifier.c \
nautilus-volume-monitor.c \
- nautilus-vfs-directory.c \
nautilus-xml-extensions.c \
$(NULL)
@@ -118,24 +127,26 @@ noinst_HEADERS = \
nautilus-background.h \
nautilus-bonobo-extensions.h \
nautilus-bookmark.h \
- nautilus-caption.h \
+ nautilus-buffered-widget.h \
nautilus-caption-table.h \
+ nautilus-caption.h \
nautilus-cdrom-extensions.h \
nautilus-debug.h \
nautilus-default-file-icon.h \
nautilus-directory-background.h \
- nautilus-directory.h \
nautilus-directory-metafile.h \
nautilus-directory-notify.h \
nautilus-directory-private.h \
+ nautilus-directory.h \
nautilus-drag.h \
nautilus-entry.h \
nautilus-file-attributes.h \
nautilus-file-changes-queue.h \
- nautilus-file.h \
nautilus-file-private.h \
nautilus-file-utilities.h \
+ nautilus-file.h \
nautilus-font-factory.h \
+ nautilus-font-picker.h \
nautilus-gdk-extensions.h \
nautilus-gdk-pixbuf-extensions.h \
nautilus-generous-bin.h \
@@ -155,9 +166,10 @@ noinst_HEADERS = \
nautilus-image.h \
nautilus-iso9660.h \
nautilus-keep-last-vertical-box.h \
+ nautilus-label.h \
nautilus-lib-self-check-functions.h \
- nautilus-link.h \
nautilus-link-set.h \
+ nautilus-link.h \
nautilus-list-column-title.h \
nautilus-list.h \
nautilus-metadata.h \
@@ -167,20 +179,22 @@ noinst_HEADERS = \
nautilus-preferences-box.h \
nautilus-preferences-dialog.h \
nautilus-preferences-group.h \
- nautilus-preferences.h \
nautilus-preferences-item.h \
nautilus-preferences-pane.h \
+ nautilus-preferences.h \
nautilus-program-chooser.h \
nautilus-program-choosing.h \
nautilus-radio-button-group.h \
+ nautilus-scalable-font.h \
+ nautilus-search-bar-criterion-private.h \
nautilus-search-bar-criterion.h \
nautilus-search-uri.h \
- nautilus-search-bar-criterion-private.h \
nautilus-self-checks.h \
nautilus-stock-dialogs.h \
- nautilus-string.h \
nautilus-string-list.h \
+ nautilus-string-map.h \
nautilus-string-picker.h \
+ nautilus-string.h \
nautilus-text-caption.h \
nautilus-theme.h \
nautilus-trash-directory.h \
@@ -193,3 +207,5 @@ noinst_HEADERS = \
nautilus-volume-monitor.h \
nautilus-xml-extensions.h \
$(NULL)
+
+$(lib_LTLIBRARIES): $(dependency_static_libs)
diff --git a/libnautilus-private/nautilus-buffered-widget.c b/libnautilus-private/nautilus-buffered-widget.c
new file mode 100644
index 000000000..e568b278d
--- /dev/null
+++ b/libnautilus-private/nautilus-buffered-widget.c
@@ -0,0 +1,668 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-buffered-widget.h - A buffered widget for alpha compositing.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+#include "nautilus-buffered-widget.h"
+
+#include "nautilus-gtk-macros.h"
+#include "nautilus-gdk-extensions.h"
+#include "nautilus-gdk-pixbuf-extensions.h"
+#include "nautilus-gtk-extensions.h"
+#include "nautilus-glib-extensions.h"
+#include "nautilus-string.h"
+#include "nautilus-background.h"
+
+#include <gtk/gtksignal.h>
+
+#include <librsvg/rsvg-ft.h>
+
+#include <libart_lgpl/art_misc.h>
+#include <libart_lgpl/art_rect.h>
+#include <libart_lgpl/art_alphagamma.h>
+#include <libart_lgpl/art_affine.h>
+
+#include <librsvg/art_render.h>
+#include <librsvg/art_render_mask.h>
+
+#include <math.h>
+#include <string.h>
+#include <png.h>
+
+/* Arguments */
+enum
+{
+ ARG_0,
+ ARG_BACKGROUND_COLOR,
+ ARG_BACKGROUND_TYPE,
+ ARG_BUFFERED_WIDGET,
+ ARG_PLACEMENT_TYPE,
+};
+
+/* Detail member struct */
+struct _NautilusBufferedWidgetDetail
+{
+ GdkGC *copy_area_gc;
+ GdkPixbuf *buffer_pixbuf;
+ GdkPixbuf *tile_pixbuf;
+};
+
+/* GdkGC refcounting macros */ \
+#define NAUTILUS_GDK_GC_UNREF_IF(_gc) \
+NAUTILUS_MACRO_BEGIN \
+ if ((_gc) != NULL) { \
+ gdk_gc_unref (_gc); \
+ (_gc) = NULL; \
+ } \
+NAUTILUS_MACRO_END
+
+#define NAUTILUS_GDK_GC_REF_IF(_gc) \
+NAUTILUS_MACRO_BEGIN \
+ if ((_gc) != NULL) { \
+ gdk_gc_ref (_gc); \
+ } \
+NAUTILUS_MACRO_END
+
+/* GtkObjectClass methods */
+static void nautilus_buffered_widget_initialize_class (NautilusBufferedWidgetClass *buffered_widget_class);
+static void nautilus_buffered_widget_initialize (NautilusBufferedWidget *buffered_widget);
+static void nautilus_buffered_widget_destroy (GtkObject *object);
+static void nautilus_buffered_widget_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+static void nautilus_buffered_widget_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+
+/* GtkWidgetClass methods */
+static void nautilus_buffered_widget_realize (GtkWidget *widget);
+static void nautilus_buffered_widget_draw (GtkWidget *widget,
+ GdkRectangle *area);
+static void nautilus_buffered_widget_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+
+/* GtkWidgetClass event methods */
+static gint nautilus_buffered_widget_expose (GtkWidget *widget,
+ GdkEventExpose *event);
+/* Private NautilusBufferedWidget things */
+static void background_appearance_changed_callback (NautilusBackground *background,
+ gpointer callback_data);
+static GdkPixbuf* buffered_widget_create_pixbuf_from_background (const NautilusBufferedWidget *buffered_widget,
+ GdkGC *gc);
+static void buffered_widget_update_pixbuf (NautilusBufferedWidget *buffered_widget);
+static GtkWidget *nautilus_gtk_widget_find_background_ancestor (GtkWidget *widget);
+static void nautilus_gdk_pixbuf_tile_alpha (GdkPixbuf *pixbuf,
+ const GdkPixbuf *tile_pixbuf,
+ guint tile_width,
+ guint tile_height,
+ gint tile_origin_x,
+ gint tile_origin_y,
+ GdkInterpType interpolation_mode,
+ guchar overall_alpha);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusBufferedWidget, nautilus_buffered_widget, GTK_TYPE_MISC)
+
+/* Class init methods */
+static void
+nautilus_buffered_widget_initialize_class (NautilusBufferedWidgetClass *buffered_widget_class)
+{
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (buffered_widget_class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (buffered_widget_class);
+
+ /* GtkObjectClass */
+ object_class->destroy = nautilus_buffered_widget_destroy;
+ object_class->set_arg = nautilus_buffered_widget_set_arg;
+ object_class->get_arg = nautilus_buffered_widget_get_arg;
+
+ /* GtkWidgetClass */
+ widget_class->realize = nautilus_buffered_widget_realize;
+ widget_class->draw = nautilus_buffered_widget_draw;
+ widget_class->expose_event = nautilus_buffered_widget_expose;
+ widget_class->size_allocate = nautilus_buffered_widget_size_allocate;
+
+ /* NautilusBufferedWidgetClass */
+ buffered_widget_class->render_buffer_pixbuf = NULL;
+}
+
+void
+nautilus_buffered_widget_initialize (NautilusBufferedWidget *buffered_widget)
+{
+ GTK_WIDGET_UNSET_FLAGS (buffered_widget, GTK_CAN_FOCUS);
+
+ GTK_WIDGET_SET_FLAGS (buffered_widget, GTK_NO_WINDOW);
+
+ buffered_widget->detail = g_new (NautilusBufferedWidgetDetail, 1);
+
+ buffered_widget->detail->copy_area_gc = NULL;
+ buffered_widget->detail->buffer_pixbuf = NULL;
+ buffered_widget->detail->tile_pixbuf = NULL;
+}
+
+/* GtkObjectClass methods */
+static void
+nautilus_buffered_widget_destroy (GtkObject *object)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (object));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (object);
+
+ NAUTILUS_GDK_GC_UNREF_IF (buffered_widget->detail->copy_area_gc);
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->buffer_pixbuf);
+ buffered_widget->detail->buffer_pixbuf = NULL;
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->tile_pixbuf);
+ buffered_widget->detail->tile_pixbuf = NULL;
+ NAUTILUS_GDK_GC_UNREF_IF (buffered_widget->detail->copy_area_gc);
+
+ g_free (buffered_widget->detail);
+
+ /* Chain destroy */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static void
+nautilus_buffered_widget_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (object));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (object);
+
+#if 0
+ switch (arg_id)
+ {
+ case ARG_PLACEMENT_TYPE:
+ buffered_widget->detail->placement_type = GTK_VALUE_ENUM (*arg);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+#endif
+}
+
+static void
+nautilus_buffered_widget_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (object));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (object);
+
+#if 0
+ switch (arg_id)
+ {
+ case ARG_PLACEMENT_TYPE:
+ GTK_VALUE_ENUM (*arg) = buffered_widget->detail->placement_type;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+#endif
+}
+
+/* GtkWidgetClass methods */
+static void
+nautilus_buffered_widget_realize (GtkWidget *widget)
+{
+ GtkWidget *background_ancestor;
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (widget));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (widget);
+
+ /* Chain realize */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, realize, (widget));
+
+ /* Create GCs */
+ buffered_widget->detail->copy_area_gc = nautilus_gdk_create_copy_area_gc (widget->window);
+
+ background_ancestor = nautilus_gtk_widget_find_background_ancestor (widget);
+
+ if (background_ancestor != NULL) {
+ NautilusBackground *background;
+
+ background = nautilus_get_widget_background (background_ancestor);
+ g_assert (NAUTILUS_IS_BACKGROUND (background));
+
+ gtk_signal_connect (GTK_OBJECT (background),
+ "appearance_changed",
+ background_appearance_changed_callback,
+ GTK_OBJECT (buffered_widget));
+ }
+ else {
+ /* g_print ("%s: No background found.\n", __FUNCTION__); */
+
+ /* FIXME: In this case, we should set a flag that indicates
+ * we need to check later for the precense of a background.
+ * Otherwise, we wont get background changes notifications,
+ * if the background gets attatched after we have been
+ * realized.
+ *
+ * Users of this code can easily work around this problem
+ * by attatching a background before the widget is realized,
+ * which is usually the case.
+ */
+ }
+}
+
+static void
+nautilus_buffered_widget_draw (GtkWidget *widget, GdkRectangle *area)
+{
+ NautilusBufferedWidget *buffered_widget;
+ GdkPoint source_point;
+ GdkRectangle destination_area;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (widget));
+ g_return_if_fail (area != NULL);
+ g_return_if_fail (GTK_WIDGET_REALIZED (widget));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (widget);
+
+ if (buffered_widget->detail->buffer_pixbuf == NULL) {
+ buffered_widget_update_pixbuf (buffered_widget);
+ }
+
+ source_point.x = 0;
+ source_point.y = 0;
+
+ destination_area.x = widget->allocation.x;
+ destination_area.y = widget->allocation.y;
+ destination_area.width = widget->allocation.width;
+ destination_area.height = widget->allocation.height;
+
+ nautilus_gdk_pixbuf_render_to_drawable (buffered_widget->detail->buffer_pixbuf,
+ widget->window,
+ buffered_widget->detail->copy_area_gc,
+ &source_point,
+ &destination_area,
+ GDK_INTERP_BILINEAR);
+}
+
+static void
+nautilus_buffered_widget_size_allocate (GtkWidget *widget, GtkAllocation* allocation)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (widget));
+ g_return_if_fail (allocation != NULL);
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (widget);
+
+ /* Assign the new allocation */
+ widget->allocation.x = allocation->x;
+ widget->allocation.y = allocation->y;
+ widget->allocation.width = MAX (1, allocation->width);
+ widget->allocation.height = MAX (1, allocation->height);
+
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->buffer_pixbuf);
+ buffered_widget->detail->buffer_pixbuf = NULL;
+}
+
+static gint
+nautilus_buffered_widget_expose (GtkWidget *widget, GdkEventExpose *event)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_val_if_fail (widget != NULL, FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (widget), FALSE);
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (widget);
+
+ nautilus_buffered_widget_draw (widget, &event->area);
+
+ return TRUE;
+}
+
+static GtkWidget *
+nautilus_gtk_widget_find_background_ancestor (GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+ while (widget != NULL) {
+ if (nautilus_widget_has_attached_background (widget)) {
+ return widget;
+ }
+
+ widget = widget->parent;
+ }
+
+ return NULL;
+}
+
+static void
+nautilus_gdk_pixbuf_tile_alpha (GdkPixbuf *pixbuf,
+ const GdkPixbuf *tile_pixbuf,
+ guint tile_width,
+ guint tile_height,
+ gint tile_origin_x,
+ gint tile_origin_y,
+ GdkInterpType interpolation_mode,
+ guchar overall_alpha)
+{
+ gint x;
+ gint y;
+ guchar *pixels;
+ guchar *tile_pixels;
+ guint num_ver_iterations;
+ guint num_hor_iterations;
+ guint i;
+ guint j;
+ guint width;
+ guint height;
+
+ g_return_if_fail (pixbuf != NULL);
+ g_return_if_fail (tile_pixbuf != NULL);
+ g_return_if_fail (tile_width <= gdk_pixbuf_get_width (tile_pixbuf));
+ g_return_if_fail (tile_height <= gdk_pixbuf_get_height (tile_pixbuf));
+ g_return_if_fail (gdk_pixbuf_get_pixels (pixbuf) != NULL);
+ g_return_if_fail (gdk_pixbuf_get_pixels (tile_pixbuf) != NULL);
+
+ pixels = gdk_pixbuf_get_pixels (pixbuf);
+ tile_pixels = gdk_pixbuf_get_pixels (tile_pixbuf);
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+
+ num_ver_iterations = ceil (height / tile_height) + 1;
+ num_hor_iterations = ceil (width / tile_width) + 1;
+
+ y = 0;
+
+ for (j = 0; j < num_ver_iterations; j++)
+ {
+ x = 0;
+
+ for (i = 0; i < num_hor_iterations; i++)
+ {
+ guint copy_width;
+ guint copy_height;
+ gint dst_x;
+ gint dst_y;
+ gint dst_x2;
+ gint dst_y2;
+
+ dst_x = x;
+ dst_y = y;
+
+ copy_width = tile_width;
+ copy_height = tile_height;
+
+ dst_x2 = dst_x + copy_width;
+ dst_y2 = dst_y + copy_height;
+
+ if (dst_x2 > width)
+ {
+ copy_width -= (dst_x2 - width);
+ }
+
+ if (dst_y2 > height)
+ {
+ copy_height -= (dst_y2 - height);
+ }
+
+ if (copy_width > 0 && copy_height > 0)
+ {
+ GdkRectangle destination_area;
+
+ destination_area.x = dst_x;
+ destination_area.y = dst_y;
+ destination_area.width = copy_width;
+ destination_area.height = copy_height;
+
+ nautilus_gdk_pixbuf_render_to_pixbuf_alpha (tile_pixbuf,
+ pixbuf,
+ &destination_area,
+ interpolation_mode,
+ overall_alpha);
+ }
+
+ x += tile_width;
+ }
+
+ y += tile_height;
+ }
+}
+
+/* Private NautilusBufferedWidget things */
+static void
+buffered_widget_update_pixbuf (NautilusBufferedWidget *buffered_widget)
+{
+ GtkWidget *widget;
+ GdkPixbuf *pixbuf_without_alpha;
+ ArtIRect clip_rect;
+ GdkPoint destination_point;
+ NautilusBufferedWidgetClass *buffered_widget_class;
+
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget));
+
+ widget = GTK_WIDGET (buffered_widget);
+
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->buffer_pixbuf);
+
+ pixbuf_without_alpha = buffered_widget_create_pixbuf_from_background (buffered_widget,
+ buffered_widget->detail->copy_area_gc);
+ buffered_widget->detail->buffer_pixbuf = gdk_pixbuf_add_alpha (pixbuf_without_alpha, FALSE, 0, 0, 0);
+
+ gdk_pixbuf_unref (pixbuf_without_alpha);
+
+ g_assert (buffered_widget->detail->buffer_pixbuf != NULL);
+
+ clip_rect.x0 = 0;
+ clip_rect.y0 = 0;
+
+ clip_rect.x1 = widget->allocation.width;
+ clip_rect.y1 = widget->allocation.height;
+
+ destination_point.x = 0;
+ destination_point.y = 0;
+
+ buffered_widget_class = NAUTILUS_BUFFERED_WIDGET_CLASS (NAUTILUS_CLASS (buffered_widget));
+ g_assert (buffered_widget_class != NULL);
+ g_assert (buffered_widget_class->render_buffer_pixbuf != NULL);
+
+ if (buffered_widget->detail->tile_pixbuf != NULL) {
+ nautilus_gdk_pixbuf_tile_alpha (buffered_widget->detail->buffer_pixbuf,
+ buffered_widget->detail->tile_pixbuf,
+ gdk_pixbuf_get_width (buffered_widget->detail->tile_pixbuf),
+ gdk_pixbuf_get_height (buffered_widget->detail->tile_pixbuf),
+ 0,
+ 0,
+ GDK_INTERP_BILINEAR,
+ 255); /* image->detail->overall_alpha */
+ }
+
+ NAUTILUS_CALL_VIRTUAL (NAUTILUS_BUFFERED_WIDGET_CLASS, buffered_widget, render_buffer_pixbuf,
+ (buffered_widget, buffered_widget->detail->buffer_pixbuf));
+}
+
+static GdkPixbuf*
+buffered_widget_create_pixbuf_from_background (const NautilusBufferedWidget *buffered_widget,
+ GdkGC *gc)
+{
+ GtkWidget *widget;
+ GdkPixbuf *pixbuf;
+ GtkWidget *background_ancestor;
+
+ g_return_val_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget), NULL);
+ g_return_val_if_fail (gc != NULL, NULL);
+
+ widget = GTK_WIDGET (buffered_widget);
+
+ background_ancestor = nautilus_gtk_widget_find_background_ancestor (widget);
+
+ if (background_ancestor != NULL) {
+ NautilusBackground *background;
+ GdkPixmap *pixmap;
+ GdkRectangle background_area;
+
+ background = nautilus_get_widget_background (background_ancestor);
+ g_assert (NAUTILUS_IS_BACKGROUND (background));
+
+ background_area.x = 0;
+ background_area.y = 0;
+ background_area.width = background_ancestor->allocation.width;
+ background_area.height = background_ancestor->allocation.height;
+
+ pixmap = gdk_pixmap_new (widget->window, background_area.width, background_area.height, -1);
+
+ nautilus_background_draw (background, pixmap, gc, &background_area, 0, 0);
+
+ pixbuf = gdk_pixbuf_get_from_drawable (NULL,
+ pixmap,
+ gdk_rgb_get_cmap (),
+ widget->allocation.x,
+ widget->allocation.y,
+ 0,
+ 0,
+ widget->allocation.width,
+ widget->allocation.height);
+
+ gdk_pixmap_unref (pixmap);
+ }
+ else {
+ GdkPixmap *pixmap;
+
+ pixmap = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1);
+
+ gtk_paint_box (widget->style,
+ pixmap,
+ GTK_STATE_NORMAL,
+ GTK_SHADOW_NONE,
+ NULL,
+ widget,
+ "entry_bg",
+ 0,
+ 0,
+ widget->allocation.width,
+ widget->allocation.height);
+
+ pixbuf = gdk_pixbuf_get_from_drawable (NULL,
+ pixmap,
+ gdk_rgb_get_cmap (),
+ 0,
+ 0,
+ 0,
+ 0,
+ widget->allocation.width,
+ widget->allocation.height);
+ }
+
+ g_assert (pixbuf != NULL);
+
+ return pixbuf;
+}
+
+static void
+background_appearance_changed_callback (NautilusBackground *background,
+ gpointer callback_data)
+{
+ NautilusBufferedWidget *buffered_widget;
+
+ g_return_if_fail (NAUTILUS_IS_BACKGROUND (background));
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (callback_data));
+
+ buffered_widget = NAUTILUS_BUFFERED_WIDGET (callback_data);
+
+ nautilus_buffered_widget_clear_buffer (buffered_widget);
+
+ gtk_widget_queue_draw (GTK_WIDGET (buffered_widget));
+}
+
+/**
+ * nautilus_buffered_widget_clear_buffer:
+ *
+ * @buffered_widget: A NautilusBufferedWidget
+ *
+ * Clear the internal buffer so that the next time the widget is drawn,
+ * the buffer will be re-composited. This is useful when you've manually
+ * done something to the widget that changes it appearance. This is mostly
+ * useful for subclasses.
+ */
+void
+nautilus_buffered_widget_clear_buffer (NautilusBufferedWidget *buffered_widget)
+{
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget));
+
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->buffer_pixbuf);
+ buffered_widget->detail->buffer_pixbuf = NULL;
+}
+
+/**
+ * nautilus_buffered_widget_set_tile_pixbuf:
+ *
+ * @buffered_widget: A NautilusBufferedWidget
+ * @pixbuf: The new tile pixbuf
+ *
+ * Change the tile pixbuf. A 'pixbuf' value of NULL, means dont use a
+ * tile pixbuf - this is the default behavior for the widget.
+ */
+void
+nautilus_buffered_widget_set_tile_pixbuf (NautilusBufferedWidget *buffered_widget,
+ GdkPixbuf *pixbuf)
+{
+ g_return_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget));
+
+ if (pixbuf != buffered_widget->detail->tile_pixbuf)
+ {
+ nautilus_gdk_pixbuf_unref_if_not_null (buffered_widget->detail->tile_pixbuf);
+
+ nautilus_gdk_pixbuf_ref_if_not_null (pixbuf);
+
+ buffered_widget->detail->tile_pixbuf = pixbuf;
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (buffered_widget));
+}
+
+/**
+ * nautilus_buffered_widget_get_tile_pixbuf:
+ *
+ * @buffered_widget: A NautilusBufferedWidget
+ *
+ * Return value: A reference to the tile_pixbuf. Needs to be unreferenced with
+ * gdk_pixbuf_unref()
+ */
+GdkPixbuf*
+nautilus_buffered_widget_get_tile_pixbuf (const NautilusBufferedWidget *buffered_widget)
+{
+ g_return_val_if_fail (NAUTILUS_IS_BUFFERED_WIDGET (buffered_widget), NULL);
+
+ nautilus_gdk_pixbuf_ref_if_not_null (buffered_widget->detail->tile_pixbuf);
+
+ return buffered_widget->detail->tile_pixbuf;
+}
diff --git a/libnautilus-private/nautilus-buffered-widget.h b/libnautilus-private/nautilus-buffered-widget.h
new file mode 100644
index 000000000..c7900badb
--- /dev/null
+++ b/libnautilus-private/nautilus-buffered-widget.h
@@ -0,0 +1,87 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-buffered-widget.h - A buffered widget for alpha compositing.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+/* NautilusBufferedWidget is a virtual widget class that encapsulates the
+ * details of finding a suitable background for compositing pixbufs.
+
+ * The background can be installed as NautilusBackground on a NautilusImage
+ * widget or any of its ancestors.
+ *
+ * The background can also be that provided by the GtkStyle attatched to the
+ * widget.
+ *
+ * The best background will automatically be found and used by the widget.
+ *
+ * Also, a tile_pixbuf can be installed to create tiling effects on top of
+ * the default background.
+ */
+
+#ifndef NAUTILUS_BUFFERED_WIDGET_H
+#define NAUTILUS_BUFFERED_WIDGET_H
+
+#include <gtk/gtkmisc.h>
+#include <libgnome/gnome-defs.h>
+
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+BEGIN_GNOME_DECLS
+
+#define NAUTILUS_TYPE_BUFFERED_WIDGET (nautilus_buffered_widget_get_type ())
+#define NAUTILUS_BUFFERED_WIDGET(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_BUFFERED_WIDGET, NautilusBufferedWidget))
+#define NAUTILUS_BUFFERED_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_BUFFERED_WIDGET, NautilusBufferedWidgetClass))
+#define NAUTILUS_IS_BUFFERED_WIDGET(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_BUFFERED_WIDGET))
+#define NAUTILUS_IS_BUFFERED_WIDGET_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_BUFFERED_WIDGET))
+
+typedef struct _NautilusBufferedWidget NautilusBufferedWidget;
+typedef struct _NautilusBufferedWidgetClass NautilusBufferedWidgetClass;
+typedef struct _NautilusBufferedWidgetDetail NautilusBufferedWidgetDetail;
+
+struct _NautilusBufferedWidget
+{
+ /* Superclass */
+ GtkMisc misc;
+
+ /* Private things */
+ NautilusBufferedWidgetDetail *detail;
+};
+
+struct _NautilusBufferedWidgetClass
+{
+ GtkMiscClass parent_class;
+
+ void (*render_buffer_pixbuf) (NautilusBufferedWidget *buffered_widget, GdkPixbuf *buffer);
+};
+
+GtkType nautilus_buffered_widget_get_type (void);
+void nautilus_buffered_widget_clear_buffer (NautilusBufferedWidget *buffered_widget);
+void nautilus_buffered_widget_set_tile_pixbuf (NautilusBufferedWidget *image,
+ GdkPixbuf *pixbuf);
+GdkPixbuf* nautilus_buffered_widget_get_tile_pixbuf (const NautilusBufferedWidget *image);
+
+END_GNOME_DECLS
+
+#endif /* NAUTILUS_BUFFERED_WIDGET_H */
+
+
diff --git a/libnautilus-private/nautilus-font-picker.c b/libnautilus-private/nautilus-font-picker.c
new file mode 100644
index 000000000..f68bd1ee1
--- /dev/null
+++ b/libnautilus-private/nautilus-font-picker.c
@@ -0,0 +1,497 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-font-picker.c - A simple widget to select scalable fonts.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+
+#include "nautilus-font-picker.h"
+#include "nautilus-gtk-macros.h"
+#include "nautilus-glib-extensions.h"
+#include "nautilus-string-picker.h"
+#include "nautilus-string.h"
+
+#include <gtk/gtklabel.h>
+#include <gtk/gtkentry.h>
+
+static const gint FONT_PICKER_SPACING = 10;
+
+/* Signals */
+typedef enum
+{
+ SELECTED_FONT_CHANGED,
+ LAST_SIGNAL
+} FontPickerSignals;
+
+struct _NautilusFontPickerDetail
+{
+ GtkWidget *family_picker;
+ GtkWidget *weight_picker;
+ GtkWidget *slant_picker;
+ GtkWidget *set_width_picker;
+
+ NautilusStringList *weight_list;
+ NautilusStringList *slant_list;
+ NautilusStringList *set_width_list;
+};
+
+/* NautilusFontPickerClass methods */
+static void nautilus_font_picker_initialize_class (NautilusFontPickerClass *klass);
+static void nautilus_font_picker_initialize (NautilusFontPicker *font_picker);
+
+
+/* GtkObjectClass methods */
+static void nautilus_font_picker_destroy (GtkObject *object);
+static void family_picker_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+static void weight_picker_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+static void slant_picker_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+static void set_width_picker_changed_callback (GtkWidget *string_picker,
+ gpointer user_data);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusFontPicker, nautilus_font_picker, GTK_TYPE_HBOX)
+
+static guint font_picker_signals[LAST_SIGNAL] = { 0 };
+
+/*
+ * NautilusFontPickerClass methods
+ */
+static void
+nautilus_font_picker_initialize_class (NautilusFontPickerClass *font_picker_class)
+{
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = GTK_OBJECT_CLASS (font_picker_class);
+ widget_class = GTK_WIDGET_CLASS (font_picker_class);
+
+ /* GtkObjectClass */
+ object_class->destroy = nautilus_font_picker_destroy;
+
+ /* Signals */
+ font_picker_signals[SELECTED_FONT_CHANGED] = gtk_signal_new ("selected_font_changed",
+ GTK_RUN_LAST,
+ object_class->type,
+ 0,
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE,
+ 0);
+
+ gtk_object_class_add_signals (object_class, font_picker_signals, LAST_SIGNAL);
+}
+
+static void
+nautilus_font_picker_initialize (NautilusFontPicker *font_picker)
+{
+ NautilusStringList *family_list;
+
+ font_picker->detail = g_new (NautilusFontPickerDetail, 1);
+
+ font_picker->detail->weight_list = NULL;
+ font_picker->detail->slant_list = NULL;
+ font_picker->detail->set_width_list = NULL;
+
+ gtk_box_set_homogeneous (GTK_BOX (font_picker), FALSE);
+ gtk_box_set_spacing (GTK_BOX (font_picker), FONT_PICKER_SPACING);
+
+ font_picker->detail->family_picker = nautilus_string_picker_new ();
+ font_picker->detail->weight_picker = nautilus_string_picker_new ();
+ font_picker->detail->slant_picker = nautilus_string_picker_new ();
+ font_picker->detail->set_width_picker = nautilus_string_picker_new ();
+
+ gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->family_picker, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->weight_picker, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (font_picker), font_picker->detail->slant_picker, TRUE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (font_picker), font_picker->detail->set_width_picker, TRUE, TRUE, 0);
+
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_picker->detail->family_picker), _("Font"));
+
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->family_picker), FALSE);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->weight_picker), FALSE);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->slant_picker), FALSE);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_picker->detail->set_width_picker), FALSE);
+
+ family_list = nautilus_scalable_font_get_font_family_list ();
+
+ nautilus_string_list_sort (family_list);
+
+ /* FIXME: Need to deal with possiblity of there being no fonts */
+ g_assert (family_list != NULL);
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker),
+ family_list);
+
+ nautilus_string_list_free (family_list);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker->detail->family_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (family_picker_changed_callback),
+ font_picker);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker->detail->weight_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (weight_picker_changed_callback),
+ font_picker);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker->detail->slant_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (slant_picker_changed_callback),
+ font_picker);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker->detail->set_width_picker),
+ "changed",
+ GTK_SIGNAL_FUNC (set_width_picker_changed_callback),
+ font_picker);
+
+ gtk_widget_show (font_picker->detail->family_picker);
+ gtk_widget_show (font_picker->detail->weight_picker);
+ gtk_widget_show (font_picker->detail->slant_picker);
+ gtk_widget_show (font_picker->detail->set_width_picker);
+
+ family_picker_changed_callback (font_picker->detail->family_picker, font_picker);
+}
+
+/* GtkObjectClass methods */
+static void
+nautilus_font_picker_destroy (GtkObject* object)
+{
+ NautilusFontPicker * font_picker;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (object));
+
+ font_picker = NAUTILUS_FONT_PICKER (object);
+
+ nautilus_string_list_free (font_picker->detail->weight_list);
+ nautilus_string_list_free (font_picker->detail->slant_list);
+ nautilus_string_list_free (font_picker->detail->set_width_list);
+
+ g_free (font_picker->detail);
+
+ /* Chain */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static void
+font_picker_update_weight_picker (NautilusFontPicker *font_picker)
+{
+ NautilusStringList *unique_weight_list;
+ char *family;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
+
+ unique_weight_list = nautilus_string_list_new_from_string_list (font_picker->detail->weight_list);
+
+ nautilus_string_list_sort (unique_weight_list);
+ nautilus_string_list_remove_duplicates (unique_weight_list);
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker),
+ unique_weight_list);
+
+ nautilus_string_list_free (unique_weight_list);
+
+ g_free (family);
+}
+
+static void
+font_picker_update_slant_picker (NautilusFontPicker *font_picker)
+{
+ NautilusStringList *unique_slant_list;
+ char *current_family;
+ char *current_weight;
+ guint i;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ current_family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
+ current_weight = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
+
+ g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
+ nautilus_string_list_get_length (font_picker->detail->weight_list));
+
+ unique_slant_list = nautilus_string_list_new ();
+
+ for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->slant_list); i++) {
+ char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
+ char *slant = nautilus_string_list_nth (font_picker->detail->slant_list, i);
+
+ if (nautilus_str_is_equal (current_weight, weight)) {
+ nautilus_string_list_insert (unique_slant_list, slant);
+ }
+
+ g_free (weight);
+ g_free (slant);
+ }
+
+ nautilus_string_list_sort (unique_slant_list);
+ nautilus_string_list_remove_duplicates (unique_slant_list);
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker),
+ unique_slant_list);
+
+ nautilus_string_list_free (unique_slant_list);
+
+ g_free (current_family);
+ g_free (current_weight);
+}
+
+static void
+font_picker_update_set_width_picker (NautilusFontPicker *font_picker)
+{
+ NautilusStringList *unique_set_width_list;
+ char *current_family;
+ char *current_weight;
+ char *current_slant;
+ guint i;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ current_family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
+ current_weight = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
+ current_slant = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker));
+
+ g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
+ nautilus_string_list_get_length (font_picker->detail->weight_list));
+
+ g_assert (nautilus_string_list_get_length (font_picker->detail->slant_list) ==
+ nautilus_string_list_get_length (font_picker->detail->set_width_list));
+
+ unique_set_width_list = nautilus_string_list_new ();
+
+ for (i = 0; i < nautilus_string_list_get_length (font_picker->detail->set_width_list); i++) {
+ char *weight = nautilus_string_list_nth (font_picker->detail->weight_list, i);
+ char *slant = nautilus_string_list_nth (font_picker->detail->slant_list, i);
+ char *set_width = nautilus_string_list_nth (font_picker->detail->set_width_list, i);
+
+ if (nautilus_str_is_equal (current_weight, weight)
+ && nautilus_str_is_equal (current_slant, slant)) {
+ nautilus_string_list_insert (unique_set_width_list, set_width);
+ }
+
+ g_free (weight);
+ g_free (slant);
+ g_free (set_width);
+ }
+
+ nautilus_string_list_sort (unique_set_width_list);
+ nautilus_string_list_remove_duplicates (unique_set_width_list);
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker),
+ unique_set_width_list);
+
+ nautilus_string_list_free (unique_set_width_list);
+
+ g_free (current_family);
+ g_free (current_weight);
+ g_free (current_slant);
+}
+
+static void
+family_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+{
+ NautilusFontPicker *font_picker;
+ char *family;
+ NautilusStringList *weight_list = NULL;
+ NautilusStringList *slant_list = NULL;
+ NautilusStringList *set_width_list = NULL;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ font_picker = NAUTILUS_FONT_PICKER (user_data);
+
+ family = nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (string_picker));
+
+ if (nautilus_scalable_font_query_font (family, &weight_list, &slant_list, &set_width_list)) {
+ nautilus_string_list_free (font_picker->detail->weight_list);
+ nautilus_string_list_free (font_picker->detail->slant_list);
+ nautilus_string_list_free (font_picker->detail->set_width_list);
+
+ font_picker->detail->weight_list = weight_list;
+ font_picker->detail->slant_list = slant_list;
+ font_picker->detail->set_width_list = set_width_list;
+
+ font_picker_update_weight_picker (font_picker);
+ font_picker_update_slant_picker (font_picker);
+ font_picker_update_set_width_picker (font_picker);
+
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+ }
+ else {
+ g_warning ("Trying to set a bogus non existant font '%s'\n", family);
+ }
+
+ g_free (family);
+}
+
+static void
+weight_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+{
+ NautilusFontPicker *font_picker;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ font_picker = NAUTILUS_FONT_PICKER (user_data);
+
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+}
+
+static void
+slant_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+{
+ NautilusFontPicker *font_picker;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ font_picker = NAUTILUS_FONT_PICKER (user_data);
+
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+}
+
+static void
+set_width_picker_changed_callback (GtkWidget *string_picker, gpointer user_data)
+{
+ NautilusFontPicker *font_picker;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (user_data));
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+
+ font_picker = NAUTILUS_FONT_PICKER (user_data);
+
+ gtk_signal_emit (GTK_OBJECT (font_picker), font_picker_signals[SELECTED_FONT_CHANGED]);
+}
+
+
+/*
+ * NautilusFontPicker public methods
+ */
+GtkWidget*
+nautilus_font_picker_new (void)
+{
+ NautilusFontPicker *font_picker;
+
+ font_picker = gtk_type_new (nautilus_font_picker_get_type ());
+
+ return GTK_WIDGET (font_picker);
+}
+
+void
+nautilus_font_picker_set_selected_family (NautilusFontPicker *font_picker,
+ const char *family)
+{
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (family != NULL);
+
+ if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker), family)) {
+ g_warning ("Trying to set a bogus family '%s'\n", family);
+ return;
+ }
+
+ nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker),
+ family);
+}
+
+void
+nautilus_font_picker_set_selected_weight (NautilusFontPicker *font_picker,
+ const char *weight)
+{
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (weight != NULL);
+
+ if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker), weight)) {
+ g_warning ("Trying to set a bogus weight '%s'\n", weight);
+ return;
+ }
+
+ nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker),
+ weight);
+}
+
+void
+nautilus_font_picker_set_selected_slant (NautilusFontPicker *font_picker,
+ const char *slant)
+{
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (slant != NULL);
+
+ if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker), slant)) {
+ g_warning ("Trying to set a bogus slant '%s'\n", slant);
+ return;
+ }
+
+ nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker),
+ slant);
+}
+
+void
+nautilus_font_picker_set_selected_set_width (NautilusFontPicker *font_picker,
+ const char *set_width)
+{
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (set_width != NULL);
+
+ if (!nautilus_string_picker_contains (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker), set_width)) {
+ g_warning ("Trying to set a bogus set_width '%s'\n", set_width);
+ return;
+ }
+
+ nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker),
+ set_width);
+}
+
+char *
+nautilus_font_picker_get_selected_family (const NautilusFontPicker *font_picker)
+{
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->family_picker));
+}
+
+char *
+nautilus_font_picker_get_selected_weight (const NautilusFontPicker *font_picker)
+{
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->weight_picker));
+}
+
+char *
+nautilus_font_picker_get_selected_slant (const NautilusFontPicker *font_picker)
+{
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->slant_picker));
+}
+
+char *
+nautilus_font_picker_get_selected_set_width (const NautilusFontPicker *font_picker)
+{
+ g_return_val_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker), NULL);
+
+ return nautilus_string_picker_get_selected_string (NAUTILUS_STRING_PICKER (font_picker->detail->set_width_picker));
+}
diff --git a/libnautilus-private/nautilus-font-picker.h b/libnautilus-private/nautilus-font-picker.h
new file mode 100644
index 000000000..381267d43
--- /dev/null
+++ b/libnautilus-private/nautilus-font-picker.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-font-picker.h - A simple widget to select scalable fonts.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#ifndef NAUTILUS_FONT_PICKER_H
+#define NAUTILUS_FONT_PICKER_H
+
+#include <gtk/gtkvbox.h>
+#include <gnome.h>
+
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+
+BEGIN_GNOME_DECLS
+
+#define NAUTILUS_TYPE_FONT_PICKER (nautilus_font_picker_get_type ())
+#define NAUTILUS_FONT_PICKER(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_FONT_PICKER, NautilusFontPicker))
+#define NAUTILUS_FONT_PICKER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_FONT_PICKER, NautilusFontPickerClass))
+#define NAUTILUS_IS_FONT_PICKER(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_FONT_PICKER))
+
+typedef struct _NautilusFontPicker NautilusFontPicker;
+typedef struct _NautilusFontPickerClass NautilusFontPickerClass;
+typedef struct _NautilusFontPickerDetail NautilusFontPickerDetail;
+
+struct _NautilusFontPicker
+{
+ /* Super Class */
+ GtkHBox hbox;
+
+ /* Private stuff */
+ NautilusFontPickerDetail *detail;
+};
+
+struct _NautilusFontPickerClass
+{
+ GtkHBoxClass parent_class;
+};
+
+GtkType nautilus_font_picker_get_type (void);
+GtkWidget* nautilus_font_picker_new (void);
+void nautilus_font_picker_set_show_weights (NautilusFontPicker *font_picker);
+void nautilus_font_picker_set_show_slants (NautilusFontPicker *font_picker);
+void nautilus_font_picker_set_show_set_widths (NautilusFontPicker *font_picker);
+void nautilus_font_picker_set_selected_family (NautilusFontPicker *font_picker,
+ const char *family);
+void nautilus_font_picker_set_selected_weight (NautilusFontPicker *font_picker,
+ const char *weight);
+void nautilus_font_picker_set_selected_slant (NautilusFontPicker *font_picker,
+ const char *slant);
+void nautilus_font_picker_set_selected_set_width (NautilusFontPicker *font_picker,
+ const char *set_width);
+char * nautilus_font_picker_get_selected_family (const NautilusFontPicker *font_picker);
+char * nautilus_font_picker_get_selected_weight (const NautilusFontPicker *font_picker);
+char * nautilus_font_picker_get_selected_slant (const NautilusFontPicker *font_picker);
+char * nautilus_font_picker_get_selected_set_width (const NautilusFontPicker *font_picker);
+
+BEGIN_GNOME_DECLS
+
+#endif /* NAUTILUS_FONT_PICKER_H */
+
+
diff --git a/libnautilus-private/nautilus-image.c b/libnautilus-private/nautilus-image.c
index e8f829533..402ad70eb 100644
--- a/libnautilus-private/nautilus-image.c
+++ b/libnautilus-private/nautilus-image.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* nautilus-image.c - A widget to display a composited pixbuf.
+/* nautilus-image.c - A widget to display a alpha composited pixbufs.
Copyright (C) 1999, 2000 Eazel, Inc.
@@ -25,25 +25,16 @@
#include <config.h>
#include "nautilus-image.h"
+#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-gdk-extensions.h"
#include "nautilus-gdk-pixbuf-extensions.h"
-#include <math.h>
-#include <string.h>
-
-/* FIXME bugzilla.eazel.com 1612:
- * We should use NautilusBackground for the background. This will simplify
- * lots of things, be more efficient, and remove the need for a lot of the
- * tiling code.
- */
-
/* Arguments */
enum
{
ARG_0,
ARG_BACKGROUND_COLOR,
- ARG_BACKGROUND_PIXBUF,
ARG_BACKGROUND_TYPE,
ARG_IMAGE,
ARG_PLACEMENT_TYPE,
@@ -52,163 +43,42 @@ enum
/* Detail member struct */
struct _NautilusImageDetail
{
- /* Attributes */
- NautilusImagePlacementType placement_type;
- NautilusImageBackgroundType background_type;
- GdkPixbuf *background_pixbuf;
- guint32 background_color;
- GdkPixbuf *pixbuf;
- GdkPoint background_tile_origin;
- guchar overall_alpha;
- gboolean background_tile_screen_relative;
-
- gchar *label_text;
- GdkFont *label_font;
-
- GdkGC *copy_area_gc;
- GdkPixbuf *buffer;
-
- /* Offsets */
- guint left_offset;
- guint right_offset;
- guint top_offset;
- guint bottom_offset;
-
- guint extra_width;
- guint extra_height;
+ GdkPixbuf *pixbuf;
+ guchar overall_alpha;
};
/* GtkObjectClass methods */
-static void nautilus_image_initialize_class (NautilusImageClass *image_class);
-static void nautilus_image_initialize (NautilusImage *image);
-static void nautilus_image_destroy (GtkObject *object);
-static void nautilus_image_set_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id);
-static void nautilus_image_get_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id);
+static void nautilus_image_initialize_class (NautilusImageClass *image_class);
+static void nautilus_image_initialize (NautilusImage *image);
+static void nautilus_image_destroy (GtkObject *object);
+static void nautilus_image_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+static void nautilus_image_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+/* GtkWidgetClass methods */
+static void nautilus_image_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
-/* GtkWidgetClass methods */
-static void nautilus_image_map (GtkWidget *widget);
-static void nautilus_image_unmap (GtkWidget *widget);
-static void nautilus_image_realize (GtkWidget *widget);
-static void nautilus_image_unrealize (GtkWidget *widget);
-static void nautilus_image_draw (GtkWidget *widget,
- GdkRectangle *area);
-static void nautilus_image_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void nautilus_image_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-
-
-/* GtkWidgetClass event methods */
-static gint nautilus_image_expose (GtkWidget *widget,
- GdkEventExpose *event);
+/* NautilusBufferedWidgetClass methods */
+static void render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
+ GdkPixbuf *buffer);
-/* Private NautilusImage things */
-static void ensure_buffer_size (NautilusImage *image,
- guint width,
- guint height);
-static GdkGC * nautilus_gdk_create_copy_area_gc (GdkWindow *window);
-static void nautilus_gdk_pixbuf_render_to_drawable (const GdkPixbuf *pixbuf,
- GdkDrawable *drawable,
- GdkGC *gc,
- const GdkPoint *source_point,
- const GdkRectangle *destination_area,
- GdkRgbDither dither);
-static void nautilus_gdk_pixbuf_render_to_pixbuf (const GdkPixbuf *pixbuf,
- GdkPixbuf *destination_pixbuf,
- const GdkPoint *source_point,
- const GdkRectangle *destination_area);
-static void nautilus_gdk_pixbuf_render_to_pixbuf_alpha (const GdkPixbuf *pixbuf,
- GdkPixbuf *destination_pixbuf,
- const GdkRectangle *destination_area,
- GdkInterpType interpolation_mode,
- guchar overall_alpha);
-static void gdk_string_dimensions (const GdkFont *font,
- const gchar *string,
- GtkRequisition *size);
-static void nautilus_gdk_pixbuf_set_to_color (GdkPixbuf *pixbuf,
- guint32 color);
-static void nautilus_gdk_pixbuf_tile (GdkPixbuf *pixbuf,
- const GdkPixbuf *tile_pixbuf,
- guint tile_width,
- guint tile_height,
- gint tile_origin_x,
- gint tile_origin_y);
-static void nautilus_gdk_pixbuf_tile_alpha (GdkPixbuf *pixbuf,
- const GdkPixbuf *tile_pixbuf,
- guint tile_width,
- guint tile_height,
- gint tile_origin_x,
- gint tile_origin_y,
- GdkInterpType interpolation_mode,
- guchar overall_alpha);
-#define NAUTILUS_ALPHA_NONE 255
-
-#define NAUTILUS_MACRO_BEGIN G_STMT_START {
-#define NAUTILUS_MACRO_END } G_STMT_END
-
-/* GdkPixbuf refcounting macros */
-#define NAUTILUS_GDK_PIXBUF_UNREF_IF(_pixbuf) \
-NAUTILUS_MACRO_BEGIN \
- if ((_pixbuf) != NULL) { \
- gdk_pixbuf_unref (_pixbuf); \
- (_pixbuf) = NULL; \
- } \
-NAUTILUS_MACRO_END
-
-#define NAUTILUS_GDK_PIXBUF_REF_IF(_pixbuf) \
-NAUTILUS_MACRO_BEGIN \
- if ((_pixbuf) != NULL) { \
- gdk_pixbuf_ref (_pixbuf); \
- } \
-NAUTILUS_MACRO_END
-
-/* GdkGC refcounting macros */ \
-#define NAUTILUS_GDK_GC_UNREF_IF(_gc) \
-NAUTILUS_MACRO_BEGIN \
- if ((_gc) != NULL) { \
- gdk_gc_unref (_gc); \
- (_gc) = NULL; \
- } \
-NAUTILUS_MACRO_END
-
-#define NAUTILUS_GDK_GC_REF_IF(_gc) \
-NAUTILUS_MACRO_BEGIN \
- if ((_gc) != NULL) { \
- gdk_gc_ref (_gc); \
- } \
-NAUTILUS_MACRO_END
-
-/* GdkFont refcounting macros */
-#define NAUTILUS_GDK_FONT_UNREF_IF(_font) \
-NAUTILUS_MACRO_BEGIN \
- if ((_font) != NULL) { \
- gdk_font_unref (_font); \
- (_font) = NULL; \
- } \
-NAUTILUS_MACRO_END
-
-#define NAUTILUS_GDK_FONT_REF_IF(_font) \
-NAUTILUS_MACRO_BEGIN \
- if ((_font) != NULL) { \
- gdk_font_ref (_font); \
- } \
-NAUTILUS_MACRO_END
-
-NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusImage, nautilus_image, GTK_TYPE_MISC)
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusImage, nautilus_image, NAUTILUS_TYPE_BUFFERED_WIDGET)
/* Class init methods */
static void
nautilus_image_initialize_class (NautilusImageClass *image_class)
{
- GtkObjectClass *object_class = GTK_OBJECT_CLASS (image_class);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (image_class);
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (image_class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (image_class);
+ NautilusBufferedWidgetClass *buffered_widget_class = NAUTILUS_BUFFERED_WIDGET_CLASS (image_class);
+#if 0
/* Arguments */
gtk_object_add_arg_type ("NautilusImage::placement_type",
GTK_TYPE_ENUM,
@@ -220,11 +90,6 @@ nautilus_image_initialize_class (NautilusImageClass *image_class)
GTK_ARG_READWRITE,
ARG_BACKGROUND_TYPE);
- gtk_object_add_arg_type ("NautilusImage::background_pixbuf",
- GTK_TYPE_OBJECT,
- GTK_ARG_READWRITE,
- ARG_BACKGROUND_PIXBUF);
-
gtk_object_add_arg_type ("NautilusImage::background_color",
GTK_TYPE_UINT,
GTK_ARG_READWRITE,
@@ -234,6 +99,7 @@ nautilus_image_initialize_class (NautilusImageClass *image_class)
GTK_TYPE_OBJECT,
GTK_ARG_READWRITE,
ARG_IMAGE);
+#endif
/* GtkObjectClass */
object_class->destroy = nautilus_image_destroy;
@@ -241,49 +107,19 @@ nautilus_image_initialize_class (NautilusImageClass *image_class)
object_class->get_arg = nautilus_image_get_arg;
/* GtkWidgetClass */
- widget_class->realize = nautilus_image_realize;
- widget_class->unrealize = nautilus_image_unrealize;
- widget_class->draw = nautilus_image_draw;
- widget_class->map = nautilus_image_map;
- widget_class->unmap = nautilus_image_unmap;
- widget_class->expose_event = nautilus_image_expose;
widget_class->size_request = nautilus_image_size_request;
- widget_class->size_allocate = nautilus_image_size_allocate;
+
+ /* NautilusBufferedWidgetClass */
+ buffered_widget_class->render_buffer_pixbuf = render_buffer_pixbuf;
}
void
nautilus_image_initialize (NautilusImage *image)
{
- GTK_WIDGET_SET_FLAGS (image, GTK_CAN_FOCUS);
- GTK_WIDGET_UNSET_FLAGS (image, GTK_NO_WINDOW);
-
image->detail = g_new (NautilusImageDetail, 1);
- image->detail->placement_type = NAUTILUS_IMAGE_PLACEMENT_CENTER;
-
- image->detail->background_color = NAUTILUS_RGB_COLOR_WHITE;
- image->detail->background_type = NAUTILUS_IMAGE_BACKGROUND_SOLID;
- image->detail->background_pixbuf = NULL;
-
image->detail->pixbuf = NULL;
-
- image->detail->buffer = NULL;
- image->detail->copy_area_gc = NULL;
- image->detail->label_text = NULL;
- image->detail->label_font = gdk_font_load ("fixed");
-
- image->detail->background_tile_origin.x = 0;
- image->detail->background_tile_origin.y = 0;
- image->detail->overall_alpha = NAUTILUS_ALPHA_NONE;
- image->detail->background_tile_screen_relative = TRUE;
-
- image->detail->left_offset = 0;
- image->detail->right_offset = 0;
- image->detail->top_offset = 0;
- image->detail->bottom_offset = 0;
-
- image->detail->extra_width = 0;
- image->detail->extra_height = 0;
+ image->detail->overall_alpha = 255;
}
/* GtkObjectClass methods */
@@ -297,14 +133,8 @@ nautilus_image_destroy (GtkObject *object)
image = NAUTILUS_IMAGE (object);
- NAUTILUS_GDK_GC_UNREF_IF (image->detail->copy_area_gc);
- NAUTILUS_GDK_FONT_UNREF_IF (image->detail->label_font);
-
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->buffer);
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->background_pixbuf);
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->pixbuf);
-
- g_free (image->detail->label_text);
+ nautilus_gdk_pixbuf_unref_if_not_null (image->detail->pixbuf);
+ image->detail->pixbuf = NULL;
g_free (image->detail);
@@ -314,8 +144,8 @@ nautilus_image_destroy (GtkObject *object)
static void
nautilus_image_set_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id)
+ GtkArg *arg,
+ guint arg_id)
{
NautilusImage *image;
@@ -324,6 +154,7 @@ nautilus_image_set_arg (GtkObject *object,
image = NAUTILUS_IMAGE (object);
+#if 0
switch (arg_id)
{
case ARG_PLACEMENT_TYPE:
@@ -334,10 +165,6 @@ nautilus_image_set_arg (GtkObject *object,
image->detail->background_type = GTK_VALUE_ENUM (*arg);
break;
- case ARG_BACKGROUND_PIXBUF:
- nautilus_image_set_background_pixbuf (image, (GdkPixbuf*) GTK_VALUE_OBJECT (*arg));
- break;
-
case ARG_BACKGROUND_COLOR:
image->detail->background_color = GTK_VALUE_UINT (*arg);
break;
@@ -349,6 +176,7 @@ nautilus_image_set_arg (GtkObject *object,
default:
g_assert_not_reached ();
}
+#endif
}
static void
@@ -363,6 +191,7 @@ nautilus_image_get_arg (GtkObject *object,
image = NAUTILUS_IMAGE (object);
+#if 0
switch (arg_id)
{
case ARG_PLACEMENT_TYPE:
@@ -373,10 +202,6 @@ nautilus_image_get_arg (GtkObject *object,
GTK_VALUE_ENUM (*arg) = image->detail->background_type;
break;
- case ARG_BACKGROUND_PIXBUF:
- GTK_VALUE_OBJECT (*arg) = (GtkObject *) nautilus_image_get_background_pixbuf (image);
- break;
-
case ARG_BACKGROUND_COLOR:
GTK_VALUE_UINT (*arg) = image->detail->background_color;
break;
@@ -388,818 +213,79 @@ nautilus_image_get_arg (GtkObject *object,
default:
g_assert_not_reached ();
}
+#endif
}
/* GtkWidgetClass methods */
-static void
-nautilus_image_realize (GtkWidget *widget)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
-
- image = NAUTILUS_IMAGE (widget);
-
- /* Chain realize */
- NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, realize, (widget));
-
- /* Create GCs */
- image->detail->copy_area_gc = nautilus_gdk_create_copy_area_gc (widget->window);
-}
-
-static void
-nautilus_image_unrealize (GtkWidget *widget)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
-
- image = NAUTILUS_IMAGE (widget);
-
- NAUTILUS_GDK_GC_UNREF_IF (image->detail->copy_area_gc);
-
- /* Chain unrealize */
- NAUTILUS_CALL_PARENT_CLASS (GTK_WIDGET_CLASS, unrealize, (widget));
-}
static void
-nautilus_image_draw (GtkWidget *widget, GdkRectangle *area)
+nautilus_image_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
{
NautilusImage *image;
- GdkPoint source_point;
- GdkRectangle destination_area;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
- g_return_if_fail (area != NULL);
-
- image = NAUTILUS_IMAGE (widget);
-
- source_point.x = area->x;
- source_point.y = area->y;
-
- destination_area.x = area->x;
- destination_area.y = area->y;
- destination_area.width = widget->allocation.width - area->x;
- destination_area.height = widget->allocation.height - area->y;
-
- nautilus_gdk_pixbuf_render_to_drawable (image->detail->buffer,
- widget->window,
- image->detail->copy_area_gc,
- &source_point,
- &destination_area,
- GDK_INTERP_NEAREST);
-}
-
-static void
-nautilus_image_size_allocate (GtkWidget *widget, GtkAllocation* allocation)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
- g_return_if_fail (allocation != NULL);
-
- image = NAUTILUS_IMAGE (widget);
-
- /* Assign the new allocation */
- widget->allocation.x = allocation->x;
- widget->allocation.y = allocation->y;
- widget->allocation.width = MAX (1, allocation->width);
- widget->allocation.height = MAX (1, allocation->height);
-
- /* If the widget is realized, move and resize its window */
- if (GTK_WIDGET_REALIZED (widget))
- {
- gdk_window_move_resize (widget->window,
- allocation->x,
- allocation->y,
- allocation->width,
- allocation->height);
-
- if (image->detail->background_tile_screen_relative)
- {
- GdkWindow *top_level;
- gint top_level_x;
- gint top_level_y;
- gint image_x;
- gint image_y;
-
-
- top_level = gdk_window_get_toplevel (widget->window);
- g_assert (top_level != NULL);
-
- gdk_window_get_origin (top_level, &top_level_x, &top_level_y);
- gdk_window_get_origin (widget->window, &image_x, &image_y);
-
-#if 0
- g_print ("2 %p:top_level = (%d,%d), %p:image = (%d,%d), diff = (%d,%d)\n",
- top_level,
- top_level_x,
- top_level_y,
- widget->window,
- image_x,
- image_y,
- top_level_x - image_x,
- top_level_y - image_y);
-#endif
-
- image->detail->background_tile_origin.x = ABS (top_level_x - image_x);
- image->detail->background_tile_origin.y = ABS (top_level_y - image_y);
- }
- }
-
- ensure_buffer_size (image, allocation->width, allocation->height);
-
- switch (image->detail->background_type)
- {
- case NAUTILUS_IMAGE_BACKGROUND_PIXBUF:
- if (image->detail->background_pixbuf != NULL)
- {
- nautilus_gdk_pixbuf_tile (image->detail->buffer,
- image->detail->background_pixbuf,
- gdk_pixbuf_get_width (image->detail->background_pixbuf),
- gdk_pixbuf_get_height (image->detail->background_pixbuf),
- image->detail->background_tile_origin.x,
- image->detail->background_tile_origin.y);
- }
- break;
-
- case NAUTILUS_IMAGE_BACKGROUND_SOLID:
- nautilus_gdk_pixbuf_set_to_color (image->detail->buffer, image->detail->background_color);
- break;
- }
-
- if (image ->detail->pixbuf != NULL)
- {
- switch (image->detail->placement_type)
- {
- case NAUTILUS_IMAGE_PLACEMENT_CENTER:
- {
- gint x;
- gint y;
-
- x = (widget->allocation.width - gdk_pixbuf_get_width (image->detail->pixbuf)) / 2;
- y = (widget->allocation.height - gdk_pixbuf_get_height (image->detail->pixbuf)) / 2;
-
- gdk_pixbuf_composite (image->detail->pixbuf,
- image->detail->buffer,
- x,
- y,
- gdk_pixbuf_get_width (image->detail->pixbuf),
- gdk_pixbuf_get_height (image->detail->pixbuf),
- (double) x,
- (double) y,
- 1.0,
- 1.0,
- GDK_INTERP_BILINEAR,
- image->detail->overall_alpha);
- }
- break;
-
- case NAUTILUS_IMAGE_PLACEMENT_TILE:
- {
- nautilus_gdk_pixbuf_tile_alpha (image->detail->buffer,
- image->detail->pixbuf,
- gdk_pixbuf_get_width (image->detail->pixbuf),
- gdk_pixbuf_get_height (image->detail->pixbuf),
- 0,
- 0,
- GDK_INTERP_BILINEAR,
- image->detail->overall_alpha);
- }
- break;
- }
- }
-
- if (image ->detail->label_text != NULL)
- {
- GtkRequisition text_size;
- gint x;
- gint y;
- ArtIRect text_rect;
-
- g_assert (image->detail->label_font != NULL);
-
- gdk_string_dimensions (image->detail->label_font,
- image ->detail->label_text,
- &text_size);
-
- x = widget->allocation.width - text_size.width - image->detail->right_offset;
- y = image->detail->top_offset;
-
-// x = (widget->allocation.width - text_size.width) / 2;
-// y = (widget->allocation.height - text_size.height) / 2;
-
- text_rect.x0 = x;
- text_rect.y0 = y;
- text_rect.x1 = x + text_size.width;
- text_rect.y1 = y + text_size.height;
-
-/* FIXME bugzilla.eazel.com xxxx:
- * Need to be able to pass in a rgb colot into the draw_text function.
- */
- nautilus_gdk_pixbuf_draw_text (image->detail->buffer,
- image->detail->label_font,
- 1.0,
- &text_rect,
- image->detail->label_text,
- NAUTILUS_RGB_COLOR_BLACK,
- image->detail->overall_alpha);
- }
-}
-
-static void
-nautilus_image_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- GtkRequisition pixbuf_size;
- GtkRequisition text_size;
- NautilusImage *image;
+ guint pixbuf_width = 0;
+ guint pixbuf_height = 0;
g_return_if_fail (widget != NULL);
g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
g_return_if_fail (requisition != NULL);
image = NAUTILUS_IMAGE (widget);
-
- requisition->width = 10;
- requisition->height = 10;
- pixbuf_size.width = 0;
- pixbuf_size.height = 0;
- text_size.width = 0;
- text_size.height = 0;
-
- if (image ->detail->pixbuf != NULL)
- {
- pixbuf_size.width = gdk_pixbuf_get_width (image->detail->pixbuf);
- pixbuf_size.height = gdk_pixbuf_get_height (image->detail->pixbuf);
+ if (image->detail->pixbuf != NULL) {
+ pixbuf_width = gdk_pixbuf_get_width (image->detail->pixbuf);
+ pixbuf_height = gdk_pixbuf_get_height (image->detail->pixbuf);
}
- if (image ->detail->label_text != NULL)
- {
- g_assert (image->detail->label_font != NULL);
-
- gdk_string_dimensions (image->detail->label_font,
- image ->detail->label_text,
- &text_size);
- }
-
- requisition->width =
- MAX (pixbuf_size.width, text_size.width) +
- image->detail->extra_width;
-
- requisition->height =
- MAX (pixbuf_size.height, text_size.height) +
- image->detail->extra_height;
-}
-
-static void
-nautilus_image_map (GtkWidget *widget)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
-
- GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
-
- image = NAUTILUS_IMAGE (widget);
-
- gdk_window_show (widget->window);
-}
-
-static void
-nautilus_image_unmap (GtkWidget *widget)
-{
- NautilusImage *image;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (widget));
-
- GTK_WIDGET_UNSET_FLAGS(widget, GTK_MAPPED);
-
- image = NAUTILUS_IMAGE (widget);
-
- gdk_window_hide (widget->window);
-}
-
-static gint
-nautilus_image_expose (GtkWidget *widget, GdkEventExpose *event)
-{
- NautilusImage *image;
-
- g_return_val_if_fail (widget != NULL, FALSE);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (widget), FALSE);
-
- image = NAUTILUS_IMAGE (widget);
-
- nautilus_image_draw (widget, &event->area);
-
- return TRUE;
+ requisition->width = MAX (2, pixbuf_width);
+ requisition->height = MAX (2, pixbuf_height);
}
/* Private NautilusImage things */
static void
-ensure_buffer_size (NautilusImage *image,
- guint new_width,
- guint new_height)
-{
- guint old_width = 0;
- guint old_height = 0;
-
- g_assert (image != NULL);
- g_assert (NAUTILUS_IS_IMAGE (image));
-
- if (new_width == 0 || new_height == 0) {
- return;
- }
-
- if (image->detail->buffer != NULL) {
- old_width = gdk_pixbuf_get_width (image->detail->buffer);
- old_height = gdk_pixbuf_get_height (image->detail->buffer);
- }
-
- if (old_width < new_width || old_height < new_height) {
- GdkPixbuf *new_pixbuf = NULL;
-
- new_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, new_width, new_height);
-
- if (image->detail->buffer) {
- gdk_pixbuf_unref (image->detail->buffer);
- }
-
- image->detail->buffer = new_pixbuf;
- }
-}
-
-static GdkGC *
-nautilus_gdk_create_copy_area_gc (GdkWindow *window)
-{
- GdkGC *copy_area_gc;
-
- g_return_val_if_fail (window != NULL, NULL);
-
- copy_area_gc = gdk_gc_new (window);
-
- gdk_gc_set_function (copy_area_gc, GDK_COPY);
-
- return copy_area_gc;
-}
-
-static void
-nautilus_gdk_pixbuf_render_to_drawable (const GdkPixbuf *pixbuf,
- GdkDrawable *drawable,
- GdkGC *gc,
- const GdkPoint *source_point,
- const GdkRectangle *destination_area,
- GdkRgbDither dither)
-{
- GdkPoint src;
- GdkRectangle dst;
- GdkPoint end;
-
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (drawable != NULL);
- g_return_if_fail (gc != NULL);
- g_return_if_fail (source_point != NULL);
- g_return_if_fail (destination_area != NULL);
- g_return_if_fail (destination_area->width > 0);
- g_return_if_fail (destination_area->height > 0);
- g_return_if_fail (source_point->x >= 0);
- g_return_if_fail (source_point->y >= 0);
-
- g_assert (gdk_pixbuf_get_width (pixbuf) > 0);
- g_assert (gdk_pixbuf_get_height (pixbuf) > 0);
-
- src = *source_point;
- dst = *destination_area;
-
- /* Clip to the left edge of the drawable */
- if (dst.x < 0)
- {
- src.x += ABS (dst.x);
- dst.x = 0;
- }
-
- /* Clip to the top edge of the drawable */
- if (dst.y < 0)
- {
- src.y += ABS (dst.y);
- dst.y = 0;
- }
-
- end.x = src.x + dst.width;
- end.y = src.y + dst.height;
-
- if (end.x >= gdk_pixbuf_get_width (pixbuf))
- {
- g_assert (dst.width >= (end.x - gdk_pixbuf_get_width (pixbuf)));
-
- dst.width -= (end.x - gdk_pixbuf_get_width (pixbuf));
- }
-
- if (end.y >= gdk_pixbuf_get_height (pixbuf))
- {
- g_assert (dst.height >= (end.y - gdk_pixbuf_get_height (pixbuf)));
-
- dst.height -= (end.y - gdk_pixbuf_get_height (pixbuf));
- }
-
- if (gdk_pixbuf_get_has_alpha (pixbuf)) {
- gdk_pixbuf_render_to_drawable_alpha ((GdkPixbuf *) pixbuf,
- drawable,
- src.x,
- src.y,
- dst.x,
- dst.y,
- dst.width,
- dst.height,
- GDK_PIXBUF_ALPHA_FULL,
- 128,
- dither,
- 0,
- 0);
-
- } else {
- gdk_pixbuf_render_to_drawable ((GdkPixbuf *) pixbuf,
- drawable,
- gc,
- src.x,
- src.y,
- dst.x,
- dst.y,
- dst.width,
- dst.height,
- dither,
- 0,
- 0);
- }
-}
-
-static void
-nautilus_gdk_pixbuf_render_to_pixbuf (const GdkPixbuf *pixbuf,
- GdkPixbuf *destination_pixbuf,
- const GdkPoint *source_point,
- const GdkRectangle *destination_area)
-{
- GdkPoint src;
- GdkRectangle dst;
- GdkPoint end;
-
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (destination_pixbuf != NULL);
- g_return_if_fail (source_point != NULL);
- g_return_if_fail (source_point->x >= 0);
- g_return_if_fail (source_point->y >= 0);
- g_return_if_fail (destination_area != NULL);
- g_return_if_fail (destination_area->width > 0);
- g_return_if_fail (destination_area->height > 0);
-
- src = *source_point;
- dst = *destination_area;
-
- /* Clip to the left edge of the drawable */
- if (dst.x < 0)
- {
- src.x += ABS (dst.x);
- dst.x = 0;
- }
-
- /* Clip to the top edge of the drawable */
- if (dst.y < 0)
- {
- src.y += ABS (dst.y);
- dst.y = 0;
- }
-
- end.x = src.x + dst.width;
- end.y = src.y + dst.height;
-
- if (end.x >= gdk_pixbuf_get_width (pixbuf))
- {
- g_assert (dst.width >= (end.x - gdk_pixbuf_get_width (pixbuf)));
-
- dst.width -= (end.x - gdk_pixbuf_get_width (pixbuf));
- }
-
- if (end.y >= gdk_pixbuf_get_height (pixbuf))
- {
- g_assert (dst.height >= (end.y - gdk_pixbuf_get_height (pixbuf)));
-
- dst.height -= (end.y - gdk_pixbuf_get_height (pixbuf));
- }
-
- gdk_pixbuf_copy_area ((GdkPixbuf *) pixbuf,
- src.x,
- src.y,
- dst.width,
- dst.height,
- destination_pixbuf,
- dst.x,
- dst.y);
-}
-
-static void
-nautilus_gdk_pixbuf_render_to_pixbuf_alpha (const GdkPixbuf *pixbuf,
- GdkPixbuf *destination_pixbuf,
- const GdkRectangle *destination_area,
- GdkInterpType interpolation_mode,
- guchar overall_alpha)
+render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget, GdkPixbuf *buffer)
{
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (destination_pixbuf != NULL);
- g_return_if_fail (destination_area != NULL);
- g_return_if_fail (destination_area->width > 0);
- g_return_if_fail (destination_area->height > 0);
-
- gdk_pixbuf_composite (pixbuf,
- destination_pixbuf,
- destination_area->x,
- destination_area->y,
- destination_area->width,
- destination_area->height,
- (double) destination_area->x,
- (double) destination_area->y,
- 1.0,
- 1.0,
- interpolation_mode,
- overall_alpha);
-}
+ NautilusImage *image;
+ GtkWidget *widget;
-static void
-gdk_string_dimensions (const GdkFont *font,
- const gchar *string,
- GtkRequisition *size)
-{
- g_return_if_fail (font != NULL);
- g_return_if_fail (size != NULL);
+ g_return_if_fail (NAUTILUS_IS_IMAGE (buffered_widget));
+ g_return_if_fail (buffer != NULL);
- size->width = 0;
- size->height = 0;
+ image = NAUTILUS_IMAGE (buffered_widget);
+ widget = GTK_WIDGET (buffered_widget);
- if (string && (strlen (string) > 0))
- {
- gint width;
- gint lbearing;
- gint rbearing;
- gint ascent;
- gint descent;
-
- gdk_text_extents ((GdkFont *) font,
- string,
- strlen (string),
- &lbearing,
- &rbearing,
- &width,
- &ascent,
- &descent);
-
- size->width = width;
- size->height = ascent + descent;
- }
-}
+ if (image->detail->pixbuf != NULL) {
+ gint x;
+ gint y;
+ guint width = gdk_pixbuf_get_width (image->detail->pixbuf);
+ guint height = gdk_pixbuf_get_height (image->detail->pixbuf);
-static void
-nautilus_gdk_pixbuf_set_to_color (GdkPixbuf *pixbuf,
- guint32 color)
-{
- guchar *pixels;
- guint width;
- guint height;
- guint rowstride;
- guint x;
- guint y;
- guchar *offset;
-
- g_return_if_fail (pixbuf != NULL);
-
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
- rowstride = gdk_pixbuf_get_rowstride (pixbuf);
- pixels = gdk_pixbuf_get_pixels (pixbuf);
-
- if (gdk_pixbuf_get_has_alpha (pixbuf))
- {
- for (y = 0; y < height; y++)
- {
- offset = pixels + y * rowstride;
-
- for (x = 0; x < width; x++)
- {
- *offset++ = NAUTILUS_RGBA_COLOR_GET_R (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_G (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_B (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_A (color);
- }
+ if (width <= widget->allocation.width) {
+ x = (widget->allocation.width - width) / 2;
}
- }
- else
- {
- for (y = 0; y < height; y++)
- {
- offset = pixels + y * rowstride;
-
- for (x = 0; x < width; x++)
- {
- *offset++ = NAUTILUS_RGBA_COLOR_GET_R (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_G (color);
- *offset++ = NAUTILUS_RGBA_COLOR_GET_B (color);
- }
+ else {
+ x = - (width - widget->allocation.width) / 2;
}
- }
-}
-
-/* FIXME bugzilla.eazel.com 1612:
- * Tile origin should be respected. Should be fixed when I use NautilusBackground.
- */
-static void
-nautilus_gdk_pixbuf_tile (GdkPixbuf *pixbuf,
- const GdkPixbuf *tile_pixbuf,
- guint tile_width,
- guint tile_height,
- gint tile_origin_x,
- gint tile_origin_y)
-{
- gint x;
- gint y;
- guchar *pixels;
- guchar *tile_pixels;
- guint num_ver_iterations;
- guint num_hor_iterations;
- guint i;
- guint j;
- guint width;
- guint height;
-
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (tile_pixbuf != NULL);
- g_return_if_fail (tile_width <= gdk_pixbuf_get_width (tile_pixbuf));
- g_return_if_fail (tile_height <= gdk_pixbuf_get_height (tile_pixbuf));
- g_return_if_fail (gdk_pixbuf_get_pixels (pixbuf) != NULL);
- g_return_if_fail (gdk_pixbuf_get_pixels (tile_pixbuf) != NULL);
-
- pixels = gdk_pixbuf_get_pixels (pixbuf);
- tile_pixels = gdk_pixbuf_get_pixels (tile_pixbuf);
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
-
- num_ver_iterations = ceil (height / tile_height) + 1;
- num_hor_iterations = ceil (width / tile_width) + 1;
-
- y = 0;
- for (j = 0; j < num_ver_iterations; j++)
- {
- x = 0;
-
- for (i = 0; i < num_hor_iterations; i++)
- {
- guint copy_width;
- guint copy_height;
- gint dst_x;
- gint dst_y;
- gint dst_x2;
- gint dst_y2;
-
- dst_x = x;
- dst_y = y;
-
- copy_width = tile_width;
- copy_height = tile_height;
-
- dst_x2 = dst_x + copy_width;
- dst_y2 = dst_y + copy_height;
-
- if (dst_x2 > width)
- {
- copy_width -= (dst_x2 - width);
- }
-
- if (dst_y2 > height)
- {
- copy_height -= (dst_y2 - height);
- }
-
- if (copy_width > 0 && copy_height > 0)
- {
- GdkPoint source_point;
- GdkRectangle destination_area;
-
- source_point.x = 0;
- source_point.y = 0;
-
- destination_area.x = dst_x;
- destination_area.y = dst_y;
- destination_area.width = copy_width;
- destination_area.height = copy_height;
-
- nautilus_gdk_pixbuf_render_to_pixbuf (tile_pixbuf,
- pixbuf,
- &source_point,
- &destination_area);
- }
-
- x += tile_width;
+ if (height <= widget->allocation.height) {
+ y = (widget->allocation.height - height) / 2;
}
-
- y += tile_height;
- }
-}
-
-static void
-nautilus_gdk_pixbuf_tile_alpha (GdkPixbuf *pixbuf,
- const GdkPixbuf *tile_pixbuf,
- guint tile_width,
- guint tile_height,
- gint tile_origin_x,
- gint tile_origin_y,
- GdkInterpType interpolation_mode,
- guchar overall_alpha)
-{
- gint x;
- gint y;
- guchar *pixels;
- guchar *tile_pixels;
- guint num_ver_iterations;
- guint num_hor_iterations;
- guint i;
- guint j;
- guint width;
- guint height;
-
- g_return_if_fail (pixbuf != NULL);
- g_return_if_fail (tile_pixbuf != NULL);
- g_return_if_fail (tile_width <= gdk_pixbuf_get_width (tile_pixbuf));
- g_return_if_fail (tile_height <= gdk_pixbuf_get_height (tile_pixbuf));
- g_return_if_fail (gdk_pixbuf_get_pixels (pixbuf) != NULL);
- g_return_if_fail (gdk_pixbuf_get_pixels (tile_pixbuf) != NULL);
-
- pixels = gdk_pixbuf_get_pixels (pixbuf);
- tile_pixels = gdk_pixbuf_get_pixels (tile_pixbuf);
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
-
- num_ver_iterations = ceil (height / tile_height) + 1;
- num_hor_iterations = ceil (width / tile_width) + 1;
-
- y = 0;
-
- for (j = 0; j < num_ver_iterations; j++)
- {
- x = 0;
-
- for (i = 0; i < num_hor_iterations; i++)
- {
- guint copy_width;
- guint copy_height;
- gint dst_x;
- gint dst_y;
- gint dst_x2;
- gint dst_y2;
-
- dst_x = x;
- dst_y = y;
-
- copy_width = tile_width;
- copy_height = tile_height;
-
- dst_x2 = dst_x + copy_width;
- dst_y2 = dst_y + copy_height;
-
- if (dst_x2 > width)
- {
- copy_width -= (dst_x2 - width);
- }
-
- if (dst_y2 > height)
- {
- copy_height -= (dst_y2 - height);
- }
-
- if (copy_width > 0 && copy_height > 0)
- {
- GdkRectangle destination_area;
-
- destination_area.x = dst_x;
- destination_area.y = dst_y;
- destination_area.width = copy_width;
- destination_area.height = copy_height;
-
- nautilus_gdk_pixbuf_render_to_pixbuf_alpha (tile_pixbuf,
- pixbuf,
- &destination_area,
- interpolation_mode,
- overall_alpha);
- }
-
- x += tile_width;
+ else {
+ y = - (height - widget->allocation.height) / 2;
}
- y += tile_height;
+ gdk_pixbuf_composite (image->detail->pixbuf,
+ buffer,
+ x,
+ y,
+ width,
+ height,
+ (double) x,
+ (double) y,
+ 1.0,
+ 1.0,
+ GDK_INTERP_BILINEAR,
+ image->detail->overall_alpha);
}
}
@@ -1211,121 +297,14 @@ nautilus_image_new (void)
}
void
-nautilus_image_set_background_pixbuf (NautilusImage *image, GdkPixbuf *background_pixbuf)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- if (background_pixbuf != image->detail->background_pixbuf)
- {
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->background_pixbuf);
-
- NAUTILUS_GDK_PIXBUF_REF_IF (background_pixbuf);
-
- image->detail->background_pixbuf = background_pixbuf;
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-GdkPixbuf*
-nautilus_image_get_background_pixbuf (const NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, NULL);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
-
- NAUTILUS_GDK_PIXBUF_REF_IF (image->detail->background_pixbuf);
-
- return image->detail->background_pixbuf;
-}
-
-void
-nautilus_image_set_background_type (NautilusImage *image, NautilusImageBackgroundType background_type)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- if (background_type == image->detail->background_type)
- {
- return;
- }
-
- image->detail->background_type = background_type;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-NautilusImageBackgroundType
-nautilus_image_get_background_type (const NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, 0);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
-
- return image->detail->background_type;
-}
-
-void
-nautilus_image_set_background_color (NautilusImage *image, guint32 background_color)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- if (background_color == image->detail->background_color)
- {
- return;
- }
-
- image->detail->background_color = background_color;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-guint32
-nautilus_image_get_background_color (const NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, 0);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
-
- return image->detail->background_color;
-}
-
-void
-nautilus_image_set_placement_type (NautilusImage *image, NautilusImagePlacementType placement_type)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- if (placement_type == image->detail->placement_type)
- {
- return;
- }
-
- image->detail->placement_type = placement_type;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-NautilusImagePlacementType
-nautilus_image_get_placement_type (const NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, 0);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), 0);
-
- return image->detail->placement_type;
-}
-
-void
nautilus_image_set_pixbuf (NautilusImage *image, GdkPixbuf *pixbuf)
{
- g_return_if_fail (image != NULL);
g_return_if_fail (NAUTILUS_IS_IMAGE (image));
if (pixbuf != image->detail->pixbuf)
{
- NAUTILUS_GDK_PIXBUF_UNREF_IF (image->detail->pixbuf);
-
- NAUTILUS_GDK_PIXBUF_REF_IF (pixbuf);
-
+ nautilus_gdk_pixbuf_unref_if_not_null (image->detail->pixbuf);
+ nautilus_gdk_pixbuf_ref_if_not_null (pixbuf);
image->detail->pixbuf = pixbuf;
}
@@ -1335,145 +314,22 @@ nautilus_image_set_pixbuf (NautilusImage *image, GdkPixbuf *pixbuf)
GdkPixbuf*
nautilus_image_get_pixbuf (const NautilusImage *image)
{
- g_return_val_if_fail (image != NULL, NULL);
g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
- NAUTILUS_GDK_PIXBUF_REF_IF (image->detail->pixbuf);
+ nautilus_gdk_pixbuf_ref_if_not_null (image->detail->pixbuf);
return image->detail->pixbuf;
}
void
nautilus_image_set_overall_alpha (NautilusImage *image,
- guchar pixbuf_alpha)
+ guchar pixbuf_alpha)
{
- g_return_if_fail (image != NULL);
g_return_if_fail (NAUTILUS_IS_IMAGE (image));
image->detail->overall_alpha = pixbuf_alpha;
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_label_text (NautilusImage *image,
- const gchar *text)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- g_free (image->detail->label_text);
+ nautilus_buffered_widget_clear_buffer (NAUTILUS_BUFFERED_WIDGET (image));
- image->detail->label_text = text ? g_strdup (text) : NULL;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-gchar*
-nautilus_image_get_label_text (NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, NULL);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
-
- return image->detail->label_text ? g_strdup (image->detail->label_text) : NULL;
-}
-
-void
-nautilus_image_set_label_font (NautilusImage *image,
- GdkFont *font)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- NAUTILUS_GDK_FONT_UNREF_IF (image->detail->label_font);
-
- image->detail->label_font = font;
-
- NAUTILUS_GDK_FONT_REF_IF (image->detail->label_font);
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-GdkFont *
-nautilus_image_get_label_font (NautilusImage *image)
-{
- g_return_val_if_fail (image != NULL, NULL);
- g_return_val_if_fail (NAUTILUS_IS_IMAGE (image), NULL);
-
- NAUTILUS_GDK_FONT_REF_IF (image->detail->label_font);
-
- return image->detail->label_font;
+ gtk_widget_queue_draw (GTK_WIDGET (image));
}
-
-void
-nautilus_image_set_left_offset (NautilusImage *image,
- guint left_offset)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->left_offset = left_offset;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_right_offset (NautilusImage *image,
- guint right_offset)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->right_offset = right_offset;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_top_offset (NautilusImage *image,
- guint top_offset)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->top_offset = top_offset;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_bottom_offset (NautilusImage *image,
- guint bottom_offset)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->bottom_offset = bottom_offset;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_extra_width (NautilusImage *image,
- guint extra_width)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->extra_width = extra_width;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
-void
-nautilus_image_set_extra_height (NautilusImage *image,
- guint extra_height)
-{
- g_return_if_fail (image != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (image));
-
- image->detail->extra_height = extra_height;
-
- gtk_widget_queue_resize (GTK_WIDGET (image));
-}
-
diff --git a/libnautilus-private/nautilus-image.h b/libnautilus-private/nautilus-image.h
index d304b14b5..41a41ed78 100644
--- a/libnautilus-private/nautilus-image.h
+++ b/libnautilus-private/nautilus-image.h
@@ -1,6 +1,6 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* nautilus-image.h - A widget to display a composited pixbuf.
+/* nautilus-image.h - A widget to display a alpha composited pixbufs.
Copyright (C) 1999, 2000 Eazel, Inc.
@@ -22,16 +22,25 @@
Authors: Ramiro Estrugo <ramiro@eazel.com>
*/
+/* NautilusImage is a widget that is capable of displaying alpha composited
+ * pixbufs over complex backgrounds. The background can be installed as
+ * NautilusBackground on a NautilusImage widget or any of its ancestors.
+ *
+ * The background can also be that provided by the GtkStyle attatched to the
+ * widget.
+ *
+ * The best background will automatically be found and used by the widget.
+ *
+ */
+
#ifndef NAUTILUS_IMAGE_H
#define NAUTILUS_IMAGE_H
-#include <gtk/gtkmisc.h>
-#include <libgnome/gnome-defs.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <libnautilus-extensions/nautilus-buffered-widget.h>
+#include <libnautilus-extensions/nautilus-scalable-font.h>
-/* NautilusImage is GtkWidget that can display a GdkPixbuf. This pixbuf
- * will be composited with full alpha support on wither a solid background
- * or a background pixbuf.
+/* NautilusImage is GtkWidget that draws a string using the high quality
+ * anti aliased librsvg/freetype.
*/
BEGIN_GNOME_DECLS
@@ -42,87 +51,31 @@ BEGIN_GNOME_DECLS
#define NAUTILUS_IS_IMAGE(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_IMAGE))
#define NAUTILUS_IS_IMAGE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_IMAGE))
-typedef struct _NautilusImage NautilusImage;
-typedef struct _NautilusImageClass NautilusImageClass;
-typedef struct _NautilusImageDetail NautilusImageDetail;
+typedef struct _NautilusImage NautilusImage;
+typedef struct _NautilusImageClass NautilusImageClass;
+typedef struct _NautilusImageDetail NautilusImageDetail;
struct _NautilusImage
{
/* Superclass */
- GtkMisc misc;
+ NautilusBufferedWidget buffered_widget;
/* Private things */
- NautilusImageDetail *detail;
+ NautilusImageDetail *detail;
};
struct _NautilusImageClass
{
- GtkMiscClass parent_class;
+ NautilusBufferedWidgetClass parent_class;
};
-typedef enum
-{
- NAUTILUS_IMAGE_PLACEMENT_TILE,
- NAUTILUS_IMAGE_PLACEMENT_CENTER
-} NautilusImagePlacementType;
-
-typedef enum
-{
- NAUTILUS_IMAGE_BACKGROUND_PIXBUF,
- NAUTILUS_IMAGE_BACKGROUND_SOLID,
-} NautilusImageBackgroundType;
-
-/* Pack RGBA components */
-#define NAUTILUS_RGBA_COLOR_PACK(_r, _g, _b, _a) \
-( ((_a) << 24) | \
- ((_r) << 16) | \
- ((_g) << 8) | \
- ((_b) << 0) )
-
-/* Access RGBA components */
-#define NAUTILUS_RGBA_COLOR_GET_R(_color) (((_color) >> 16) & 0xff)
-#define NAUTILUS_RGBA_COLOR_GET_G(_color) (((_color) >> 8) & 0xff)
-#define NAUTILUS_RGBA_COLOR_GET_B(_color) (((_color) >> 0) & 0xff)
-#define NAUTILUS_RGBA_COLOR_GET_A(_color) (((_color) >> 24) & 0xff)
-
-GtkType nautilus_image_get_type (void);
-GtkWidget * nautilus_image_new (void);
-void nautilus_image_set_background_pixbuf (NautilusImage *image,
- GdkPixbuf *background);
-GdkPixbuf* nautilus_image_get_background_pixbuf (const NautilusImage *image);
-void nautilus_image_set_background_type (NautilusImage *image,
- NautilusImageBackgroundType background_type);
-NautilusImageBackgroundType nautilus_image_get_background_type (const NautilusImage *image);
-void nautilus_image_set_placement_type (NautilusImage *image,
- NautilusImagePlacementType placement);
-NautilusImagePlacementType nautilus_image_get_placement_type (const NautilusImage *image);
-void nautilus_image_set_background_color (NautilusImage *image,
- guint32 color);
-guint32 nautilus_image_get_background_color (const NautilusImage *image);
-void nautilus_image_set_pixbuf (NautilusImage *image,
- GdkPixbuf *pixbuf);
-GdkPixbuf* nautilus_image_get_pixbuf (const NautilusImage *image);
-void nautilus_image_set_overall_alpha (NautilusImage *image,
- guchar pixbuf_alpha);
-void nautilus_image_set_label_text (NautilusImage *image,
- const gchar *text);
-gchar* nautilus_image_get_label_text (NautilusImage *image);
-void nautilus_image_set_label_font (NautilusImage *image,
- GdkFont *font);
-GdkFont* nautilus_image_get_label_font (NautilusImage *image);
-void nautilus_image_set_left_offset (NautilusImage *image,
- guint left_offset);
-void nautilus_image_set_right_offset (NautilusImage *image,
- guint right_offset);
-void nautilus_image_set_top_offset (NautilusImage *image,
- guint top_offset);
-void nautilus_image_set_bottom_offset (NautilusImage *image,
- guint bottom_offset);
-void nautilus_image_set_extra_width (NautilusImage *image,
- guint extra_width);
-void nautilus_image_set_extra_height (NautilusImage *image,
- guint extra_width);
-
+GtkType nautilus_image_get_type (void);
+GtkWidget *nautilus_image_new (void);
+void nautilus_image_set_pixbuf (NautilusImage *image,
+ GdkPixbuf *pixbuf);
+GdkPixbuf* nautilus_image_get_pixbuf (const NautilusImage *image);
+void nautilus_image_set_overall_alpha (NautilusImage *image,
+ guchar pixbuf_alpha);
END_GNOME_DECLS
diff --git a/libnautilus-private/nautilus-label.c b/libnautilus-private/nautilus-label.c
new file mode 100644
index 000000000..f756b36ec
--- /dev/null
+++ b/libnautilus-private/nautilus-label.c
@@ -0,0 +1,569 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-label.c - A widget to display a anti aliased text.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+#include "nautilus-label.h"
+
+#include "nautilus-gtk-macros.h"
+#include "nautilus-gdk-extensions.h"
+#include "nautilus-gdk-pixbuf-extensions.h"
+#include "nautilus-string.h"
+
+/* Arguments */
+enum
+{
+ ARG_0,
+ ARG_BACKGROUND_COLOR,
+ ARG_BACKGROUND_TYPE,
+ ARG_LABEL,
+ ARG_PLACEMENT_TYPE,
+};
+
+/* Detail member struct */
+struct _NautilusLabelDetail
+{
+ /* Text */
+ char *text;
+ guint32 text_color;
+ guchar text_alpha;
+ guint text_width;
+ guint text_height;
+ GtkJustification text_justification;
+ guint line_offset;
+
+ /* Font */
+ NautilusScalableFont *font;
+ guint font_size;
+
+ /* Text lines */
+ char **text_lines;
+ guint *text_line_widths;
+ guint *text_line_heights;
+ guint num_text_lines;
+ guint max_text_line_width;
+ guint total_text_line_height;
+};
+
+/* GtkObjectClass methods */
+static void nautilus_label_initialize_class (NautilusLabelClass *label_class);
+static void nautilus_label_initialize (NautilusLabel *label);
+static void nautilus_label_destroy (GtkObject *object);
+static void nautilus_label_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+static void nautilus_label_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id);
+
+/* GtkWidgetClass methods */
+static void nautilus_label_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+
+/* NautilusBufferedWidgetClass methods */
+static void render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget,
+ GdkPixbuf *buffer);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusLabel, nautilus_label, NAUTILUS_TYPE_BUFFERED_WIDGET)
+
+/* Class init methods */
+static void
+nautilus_label_initialize_class (NautilusLabelClass *label_class)
+{
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (label_class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (label_class);
+ NautilusBufferedWidgetClass *buffered_widget_class = NAUTILUS_BUFFERED_WIDGET_CLASS (label_class);
+
+#if 0
+ /* Arguments */
+ gtk_object_add_arg_type ("NautilusLabel::placement_type",
+ GTK_TYPE_ENUM,
+ GTK_ARG_READWRITE,
+ ARG_PLACEMENT_TYPE);
+
+ gtk_object_add_arg_type ("NautilusLabel::background_type",
+ GTK_TYPE_ENUM,
+ GTK_ARG_READWRITE,
+ ARG_BACKGROUND_TYPE);
+
+ gtk_object_add_arg_type ("NautilusLabel::background_color",
+ GTK_TYPE_UINT,
+ GTK_ARG_READWRITE,
+ ARG_BACKGROUND_COLOR);
+
+ gtk_object_add_arg_type ("NautilusLabel::label",
+ GTK_TYPE_OBJECT,
+ GTK_ARG_READWRITE,
+ ARG_LABEL);
+#endif
+
+ /* GtkObjectClass */
+ object_class->destroy = nautilus_label_destroy;
+ object_class->set_arg = nautilus_label_set_arg;
+ object_class->get_arg = nautilus_label_get_arg;
+
+ /* GtkWidgetClass */
+ widget_class->size_request = nautilus_label_size_request;
+
+ /* NautilusBufferedWidgetClass */
+ buffered_widget_class->render_buffer_pixbuf = render_buffer_pixbuf;
+}
+
+void
+nautilus_label_initialize (NautilusLabel *label)
+{
+ label->detail = g_new (NautilusLabelDetail, 1);
+
+ label->detail->text = NULL;
+
+ label->detail->font = nautilus_scalable_font_get_default_font ();
+ label->detail->font_size = 48;
+
+ label->detail->text_color = NAUTILUS_RGBA_COLOR_PACK (0, 0, 0, 255);
+ label->detail->text_alpha = 255;
+ label->detail->text_width = 0;
+ label->detail->text_height = 0;
+ label->detail->text_justification = GTK_JUSTIFY_CENTER;
+
+ label->detail->num_text_lines = 0;
+ label->detail->max_text_line_width = 0;
+ label->detail->total_text_line_height = 0;
+ label->detail->text_lines = NULL;
+ label->detail->text_line_widths = NULL;
+ label->detail->text_line_heights = NULL;
+
+ label->detail->line_offset = 2;
+}
+
+/* GtkObjectClass methods */
+static void
+nautilus_label_destroy (GtkObject *object)
+{
+ NautilusLabel *label;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (object));
+
+ label = NAUTILUS_LABEL (object);
+
+ g_free (label->detail->text);
+
+ g_strfreev (label->detail->text_lines);
+ g_free (label->detail->text_line_widths);
+ g_free (label->detail->text_line_heights);
+
+ g_free (label->detail);
+
+ /* Chain destroy */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static void
+nautilus_label_set_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ NautilusLabel *label;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (object));
+
+ label = NAUTILUS_LABEL (object);
+
+#if 0
+ switch (arg_id)
+ {
+ case ARG_PLACEMENT_TYPE:
+ label->detail->placement_type = GTK_VALUE_ENUM (*arg);
+ break;
+
+ case ARG_BACKGROUND_TYPE:
+ label->detail->background_type = GTK_VALUE_ENUM (*arg);
+ break;
+
+ case ARG_BACKGROUND_COLOR:
+ label->detail->background_color = GTK_VALUE_UINT (*arg);
+ break;
+
+ case ARG_LABEL:
+ nautilus_label_set_pixbuf (label, (GdkPixbuf*) GTK_VALUE_OBJECT (*arg));
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+#endif
+}
+
+static void
+nautilus_label_get_arg (GtkObject *object,
+ GtkArg *arg,
+ guint arg_id)
+{
+ NautilusLabel *label;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (object));
+
+ label = NAUTILUS_LABEL (object);
+
+#if 0
+ switch (arg_id)
+ {
+ case ARG_PLACEMENT_TYPE:
+ GTK_VALUE_ENUM (*arg) = label->detail->placement_type;
+ break;
+
+ case ARG_BACKGROUND_TYPE:
+ GTK_VALUE_ENUM (*arg) = label->detail->background_type;
+ break;
+
+ case ARG_BACKGROUND_COLOR:
+ GTK_VALUE_UINT (*arg) = label->detail->background_color;
+ break;
+
+ case ARG_LABEL:
+ GTK_VALUE_OBJECT (*arg) = (GtkObject *) nautilus_label_get_pixbuf (label);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+#endif
+}
+
+/* GtkWidgetClass methods */
+static void
+nautilus_label_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ NautilusLabel *label;
+ guint text_width = 0;
+ guint text_height = 0;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (widget));
+ g_return_if_fail (requisition != NULL);
+
+ label = NAUTILUS_LABEL (widget);
+
+ if (label->detail->num_text_lines > 0) {
+ text_width = label->detail->max_text_line_width;
+ text_height = label->detail->total_text_line_height;
+
+ text_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
+ }
+
+ requisition->width = MAX (2, text_width);
+ requisition->height = MAX (2, text_height);
+}
+
+/* Private NautilusLabel things */
+static void
+render_buffer_pixbuf (NautilusBufferedWidget *buffered_widget, GdkPixbuf *buffer)
+{
+ NautilusLabel *label;
+ GtkWidget *widget;
+ ArtIRect area;
+ guint total_text_width;
+ guint total_text_height;
+
+
+ g_return_if_fail (NAUTILUS_IS_LABEL (buffered_widget));
+ g_return_if_fail (buffer != NULL);
+
+ label = NAUTILUS_LABEL (buffered_widget);
+
+ if (label->detail->num_text_lines == 0) {
+ return;
+ }
+
+ widget = GTK_WIDGET (buffered_widget);
+
+ total_text_width = label->detail->max_text_line_width;
+ total_text_height = label->detail->total_text_line_height;
+ total_text_height += ((label->detail->num_text_lines - 1) * label->detail->line_offset);
+
+
+ if (total_text_width <= widget->allocation.width) {
+ area.x0 = (widget->allocation.width - total_text_width) / 2;
+ }
+ else {
+ area.x0 = - (total_text_width - widget->allocation.width) / 2;
+ }
+
+ if (total_text_height <= widget->allocation.height) {
+ area.y0 = (widget->allocation.height - total_text_height) / 2;
+ }
+ else {
+ area.y0 = - (total_text_height - widget->allocation.height) / 2;
+ }
+
+ area.x1 = area.x0 + total_text_width;
+ area.y1 = area.y0 + total_text_width;
+
+ if (label->detail->num_text_lines > 0) {
+ nautilus_scalable_font_draw_text_lines (label->detail->font,
+ buffer,
+ &area,
+ label->detail->font_size,
+ label->detail->font_size,
+ (const char **) label->detail->text_lines,
+ label->detail->text_line_widths,
+ label->detail->text_line_heights,
+ label->detail->text_justification,
+ label->detail->num_text_lines,
+ label->detail->line_offset,
+ label->detail->text_color,
+ label->detail->text_alpha);
+ }
+}
+
+/* Public NautilusLabel */
+GtkWidget*
+nautilus_label_new (void)
+{
+ return GTK_WIDGET (gtk_type_new (nautilus_label_get_type ()));
+}
+
+void
+nautilus_label_set_text (NautilusLabel *label,
+ const gchar *text)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+
+ g_free (label->detail->text);
+ label->detail->text = text ? g_strdup (text) : NULL;
+
+ g_strfreev (label->detail->text_lines);
+ g_free (label->detail->text_line_widths);
+ g_free (label->detail->text_line_heights);
+ label->detail->text_lines = NULL;
+ label->detail->text_line_widths = NULL;
+ label->detail->text_line_heights = NULL;
+
+ label->detail->num_text_lines = 0;
+
+ label->detail->max_text_line_width = 0;
+ label->detail->total_text_line_height = 0;
+
+ label->detail->text_lines = NULL;
+
+ if (nautilus_strlen (label->detail->text) > 0) {
+ label->detail->num_text_lines = nautilus_str_count_characters (label->detail->text, '\n') + 1;
+
+ label->detail->text_lines = g_strsplit (label->detail->text, "\n", -1);
+
+ label->detail->text_line_widths = g_new (guint, label->detail->num_text_lines);
+ label->detail->text_line_heights = g_new (guint, label->detail->num_text_lines);
+
+ nautilus_scalable_font_measure_text_lines (label->detail->font,
+ label->detail->font_size,
+ label->detail->font_size,
+ (const char **) label->detail->text_lines,
+ label->detail->num_text_lines,
+ label->detail->text_line_widths,
+ label->detail->text_line_heights,
+ &label->detail->max_text_line_width,
+ &label->detail->total_text_line_height);
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+}
+
+gchar*
+nautilus_label_get_text (NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), NULL);
+
+ return label->detail->text ? g_strdup (label->detail->text) : NULL;
+}
+
+void
+nautilus_label_set_font (NautilusLabel *label,
+ NautilusScalableFont *font)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+
+ if (label->detail->font != NULL) {
+ gtk_object_unref (GTK_OBJECT (label->detail->font));
+ label->detail->font = NULL;
+ }
+
+ gtk_object_ref (GTK_OBJECT (font));
+
+ label->detail->font = font;
+
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+}
+
+NautilusScalableFont *
+nautilus_label_get_font (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ if (label->detail->font != NULL) {
+ gtk_object_ref (GTK_OBJECT (label->detail->font));
+ }
+
+ return label->detail->font;
+}
+
+void
+nautilus_label_set_font_size (NautilusLabel *label,
+ guint font_size)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+ g_return_if_fail (font_size > 0);
+
+ if (label->detail->font_size == font_size) {
+ return;
+ }
+
+ label->detail->font_size = font_size;
+
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+}
+
+guint
+nautilus_label_get_font_size (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->font_size;
+}
+
+void
+nautilus_label_set_text_color (NautilusLabel *label,
+ guint32 text_color)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+
+ label->detail->text_color = text_color;
+
+ nautilus_buffered_widget_clear_buffer (NAUTILUS_BUFFERED_WIDGET (label));
+
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+}
+
+guint32
+nautilus_label_get_text_color (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->text_color;
+}
+
+void
+nautilus_label_set_text_alpha (NautilusLabel *label,
+ guchar text_alpha)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+
+ label->detail->text_alpha = text_alpha;
+
+ nautilus_buffered_widget_clear_buffer (NAUTILUS_BUFFERED_WIDGET (label));
+
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+}
+
+guchar
+nautilus_label_get_text_alpha (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->text_alpha;
+}
+
+void
+nautilus_label_set_text_justification (NautilusLabel *label,
+ GtkJustification justification)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+ g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL);
+
+ if (label->detail->text_justification == justification) {
+ return;
+ }
+
+ label->detail->text_justification = justification;
+
+ nautilus_buffered_widget_clear_buffer (NAUTILUS_BUFFERED_WIDGET (label));
+
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+}
+
+GtkJustification
+nautilus_label_get_text_justification (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->text_justification;
+}
+
+/**
+ * nautilus_label_get_line_offset:
+ *
+ * @label: A NautilusLabel
+ *
+ * Change the line offset. Obviously, this is only interesting if the
+ * label is displaying text that contains '\n' characters.
+ *
+ */
+void
+nautilus_label_set_line_offset (NautilusLabel *label,
+ guint line_offset)
+{
+ g_return_if_fail (NAUTILUS_IS_LABEL (label));
+
+ if (label->detail->line_offset == line_offset) {
+ return;
+ }
+
+ label->detail->line_offset = line_offset;
+
+ gtk_widget_queue_resize (GTK_WIDGET (label));
+}
+
+/**
+ * nautilus_label_get_line_offset:
+ *
+ * @label: A NautilusLabel
+ *
+ * Return value: The line offset in pixels.
+ */
+guint
+nautilus_label_get_line_offset (const NautilusLabel *label)
+{
+ g_return_val_if_fail (label != NULL, 0);
+ g_return_val_if_fail (NAUTILUS_IS_LABEL (label), 0);
+
+ return label->detail->line_offset;
+}
diff --git a/libnautilus-private/nautilus-label.h b/libnautilus-private/nautilus-label.h
new file mode 100644
index 000000000..58b76ed39
--- /dev/null
+++ b/libnautilus-private/nautilus-label.h
@@ -0,0 +1,102 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-label.h - A widget to display a anti aliased text.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+/* NautilusLabel is a widget that is capable of display anti aliased
+ * text composited over a complex background. The background can be
+ * installed as NautilusBackground on a NautilusLabel widget or any
+ * of its ancestors. The best background will automatically be found
+ * and used by the widget.
+ *
+ * Fonts can be specified using a NautilusScalableFont object.
+ *
+ * Text can contain embedded new lines.
+ *
+ */
+
+#ifndef NAUTILUS_LABEL_H
+#define NAUTILUS_LABEL_H
+
+#include <libnautilus-extensions/nautilus-buffered-widget.h>
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+
+/* NautilusLabel is GtkWidget that draws a string using the high quality
+ * anti aliased librsvg/freetype.
+ */
+
+BEGIN_GNOME_DECLS
+
+#define NAUTILUS_TYPE_LABEL (nautilus_label_get_type ())
+#define NAUTILUS_LABEL(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_LABEL, NautilusLabel))
+#define NAUTILUS_LABEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_LABEL, NautilusLabelClass))
+#define NAUTILUS_IS_LABEL(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_LABEL))
+#define NAUTILUS_IS_LABEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_LABEL))
+
+typedef struct _NautilusLabel NautilusLabel;
+typedef struct _NautilusLabelClass NautilusLabelClass;
+typedef struct _NautilusLabelDetail NautilusLabelDetail;
+
+struct _NautilusLabel
+{
+ /* Superclass */
+ NautilusBufferedWidget buffered_widget;
+
+ /* Private things */
+ NautilusLabelDetail *detail;
+};
+
+struct _NautilusLabelClass
+{
+ NautilusBufferedWidgetClass parent_class;
+};
+
+GtkType nautilus_label_get_type (void);
+GtkWidget * nautilus_label_new (void);
+void nautilus_label_set_text (NautilusLabel *label,
+ const char *text);
+char* nautilus_label_get_text (NautilusLabel *label);
+void nautilus_label_set_font (NautilusLabel *label,
+ NautilusScalableFont *font);
+NautilusScalableFont *nautilus_label_get_font (const NautilusLabel *label);
+void nautilus_label_set_font_size (NautilusLabel *label,
+ guint font_size);
+guint nautilus_label_get_font_size (const NautilusLabel *label);
+void nautilus_label_set_text_color (NautilusLabel *label,
+ guint32 color);
+guint32 nautilus_label_get_text_color (const NautilusLabel *label);
+void nautilus_label_set_text_alpha (NautilusLabel *label,
+ guchar alpha);
+guchar nautilus_label_get_text_alpha (const NautilusLabel *label);
+void nautilus_label_set_text_justification (NautilusLabel *label,
+ GtkJustification justification);
+GtkJustification nautilus_label_get_text_justification (const NautilusLabel *label);
+void nautilus_label_set_line_offset (NautilusLabel *label,
+ guint alpha);
+guint nautilus_label_get_line_offset (const NautilusLabel *label);
+
+
+END_GNOME_DECLS
+
+#endif /* NAUTILUS_LABEL_H */
+
+
diff --git a/libnautilus-private/nautilus-lib-self-check-functions.h b/libnautilus-private/nautilus-lib-self-check-functions.h
index cadc71e70..9a6c6a584 100644
--- a/libnautilus-private/nautilus-lib-self-check-functions.h
+++ b/libnautilus-private/nautilus-lib-self-check-functions.h
@@ -41,10 +41,11 @@ void nautilus_run_lib_self_checks (void);
#define NAUTILUS_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \
macro (nautilus_self_check_string) \
macro (nautilus_self_check_string_list) \
+ macro (nautilus_self_check_string_map) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_gdk_extensions) \
- macro (nautilus_self_check_search_uri) \
- macro (nautilus_self_check_file_utilities) \
+ macro (nautilus_self_check_search_uri) \
+ macro (nautilus_self_check_file_utilities) \
macro (nautilus_self_check_background) \
macro (nautilus_self_check_directory) \
macro (nautilus_self_check_file) \
diff --git a/libnautilus-private/nautilus-scalable-font.c b/libnautilus-private/nautilus-scalable-font.c
new file mode 100644
index 000000000..b6128fd05
--- /dev/null
+++ b/libnautilus-private/nautilus-scalable-font.c
@@ -0,0 +1,1056 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-scalable-font.c - A GtkObject subclass for access to scalable fonts.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+#include "nautilus-scalable-font.h"
+
+#include "nautilus-gtk-macros.h"
+#include "nautilus-gdk-extensions.h"
+#include "nautilus-gdk-pixbuf-extensions.h"
+#include "nautilus-background.h"
+#include "nautilus-string.h"
+#include "nautilus-file-utilities.h"
+#include "nautilus-glib-extensions.h"
+
+#include <librsvg/rsvg-ft.h>
+
+#include <libart_lgpl/art_misc.h>
+#include <libart_lgpl/art_alphagamma.h>
+#include <libart_lgpl/art_affine.h>
+#include <librsvg/art_render.h>
+#include <librsvg/art_render_mask.h>
+
+#include <stdio.h>
+#include <libgnome/gnome-util.h>
+#include <ctype.h>
+
+/* FontEntry */
+typedef struct {
+ char *weight;
+ char *slant;
+ char *set_width;
+ RsvgFTFontHandle font_handle;
+ char *path;
+} FontEntry;
+
+/* FontFamilyEntry */
+typedef struct {
+ char *family;
+ GList *fonts;
+} FontFamilyEntry;
+
+
+/* Detail member struct */
+struct _NautilusScalableFontDetail
+{
+ RsvgFTFontHandle font_handle;
+};
+
+/* Global things */
+static GHashTable *global_font_family_table = NULL;
+static RsvgFTCtx *global_rsvg_ft_context = NULL;
+static NautilusScalableFont *global_default_font = NULL;
+
+static const RsvgFTFontHandle UNDEFINED_FONT_HANDLE = -1;
+
+/* GtkObjectClass methods */
+static void nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class);
+static void nautilus_scalable_font_initialize (NautilusScalableFont *font);
+static void nautilus_scalable_font_destroy (GtkObject *object);
+static void initialize_global_stuff_if_needed (void);
+
+NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusScalableFont, nautilus_scalable_font, GTK_TYPE_OBJECT)
+
+/* Class init methods */
+static void
+nautilus_scalable_font_initialize_class (NautilusScalableFontClass *font_class)
+{
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (font_class);
+
+ initialize_global_stuff_if_needed ();
+
+ /* GtkObjectClass */
+ object_class->destroy = nautilus_scalable_font_destroy;
+}
+
+void
+nautilus_scalable_font_initialize (NautilusScalableFont *font)
+{
+ font->detail = g_new (NautilusScalableFontDetail, 1);
+
+ font->detail->font_handle = UNDEFINED_FONT_HANDLE;
+}
+
+/* GtkObjectClass methods */
+static void
+nautilus_scalable_font_destroy (GtkObject *object)
+{
+ NautilusScalableFont *font;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (object));
+
+ font = NAUTILUS_SCALABLE_FONT (object);
+
+ g_free (font->detail);
+
+ /* Chain destroy */
+ NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
+}
+
+static char *
+file_as_string (const char *file_name)
+{
+ struct stat stat_info;
+ FILE *stream;
+ char *result;
+ size_t num_read;
+
+ g_return_val_if_fail (file_name != NULL, NULL);
+ g_return_val_if_fail (g_file_exists (file_name), NULL);
+
+ if (stat (file_name, &stat_info) != 0) {
+ return NULL;
+ }
+
+ if (stat_info.st_size == 0) {
+ return NULL;
+ }
+
+ stream = fopen (file_name, "r");
+
+ if (!stream) {
+ return NULL;
+ }
+
+ result = g_malloc (sizeof (char) * stat_info.st_size + 1);
+
+ num_read = fread (result, sizeof (char), stat_info.st_size, stream);
+
+ fclose (stream);
+
+ if (num_read != stat_info.st_size) {
+ g_free (result);
+ return NULL;
+ }
+
+ result[stat_info.st_size] = '\0';
+
+ return result;
+}
+
+static gboolean
+parse_font_description_file (const char *directory,
+ NautilusStringList **font_pfb_list_out,
+ NautilusStringList **font_xfld_list_out)
+{
+ char *fonts_dir_path;
+ char *fonts_dir_content;
+ NautilusStringList *tokenized_list;
+ guint i;
+ gint count;
+
+ g_return_val_if_fail (directory != NULL, FALSE);
+ g_return_val_if_fail (g_file_exists (directory), FALSE);
+ g_return_val_if_fail (font_pfb_list_out != NULL, FALSE);
+ g_return_val_if_fail (font_xfld_list_out != NULL, FALSE);
+
+ *font_pfb_list_out = NULL;
+ *font_xfld_list_out = NULL;
+
+ fonts_dir_path = g_strdup_printf ("%s/%s", directory, "fonts.dir");
+ fonts_dir_content = file_as_string (fonts_dir_path);
+ g_free (fonts_dir_path);
+
+ if (fonts_dir_content == NULL) {
+ return FALSE;
+ }
+
+ tokenized_list = nautilus_string_list_new_from_tokens (fonts_dir_content, "\n");
+ g_free (fonts_dir_content);
+
+ if (tokenized_list == NULL) {
+ return FALSE;
+ }
+
+ if (nautilus_string_list_get_length (tokenized_list) <= 1) {
+ nautilus_string_list_free (tokenized_list);
+ return FALSE;
+ }
+
+ if (!nautilus_eat_str_to_int (nautilus_string_list_nth (tokenized_list, 0), &count)) {
+ return FALSE;
+ }
+
+ *font_pfb_list_out = nautilus_string_list_new ();
+ *font_xfld_list_out = nautilus_string_list_new ();
+
+ for (i = 0; i < count; i++) {
+ char *line = nautilus_string_list_nth (tokenized_list, i + 1);
+
+ if (line != NULL) {
+ char *delimeter;
+
+ /* Look for the delimiting space */
+ delimeter = strstr (line, " ");
+ if (delimeter != NULL) {
+
+ char *font_pfb;
+ char *font_pfb_path;
+ guint pfb_length;
+
+ pfb_length = delimeter - line;
+ font_pfb = g_malloc (sizeof (char) * pfb_length + 1);
+ strncpy (font_pfb, line, pfb_length);
+ font_pfb[pfb_length] = '\0';
+
+ font_pfb_path = g_strdup_printf ("%s/%s", directory, font_pfb);
+
+ /* Make sure the pfb file exists */
+ if (g_file_exists (font_pfb_path)) {
+ while (isspace (*delimeter)) {
+ delimeter++;
+ }
+
+ nautilus_string_list_insert (*font_pfb_list_out, font_pfb_path);
+ nautilus_string_list_insert (*font_xfld_list_out, delimeter);
+ }
+
+ g_free (font_pfb);
+ g_free (font_pfb_path);
+ }
+
+ g_free (line);
+ }
+ }
+
+ nautilus_string_list_free (tokenized_list);
+
+ return TRUE;
+}
+
+/*
+ * FontEntry things
+ */
+static FontEntry*
+font_entry_new (const char *weight,
+ const char *slant,
+ const char *set_width,
+ const char *path)
+{
+ FontEntry *entry;
+
+ g_return_val_if_fail (weight != NULL, NULL);
+ g_return_val_if_fail (slant != NULL, NULL);
+ g_return_val_if_fail (set_width != NULL, NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+
+ entry = g_new (FontEntry, 1);
+
+ entry->weight = g_strdup (weight);
+ entry->slant = g_strdup (slant);
+ entry->set_width = g_strdup (set_width);
+ entry->path = g_strdup (path);
+ entry->font_handle = UNDEFINED_FONT_HANDLE;
+
+ return entry;
+}
+
+static void
+font_entry_free (FontEntry* entry)
+{
+ g_return_if_fail (entry != NULL);
+
+ g_free (entry->weight);
+ g_free (entry->slant);
+ g_free (entry->set_width);
+ g_free (entry->path);
+
+ /* These fonts arent refcounted because they are catched internally by librsvg */
+ entry->font_handle = UNDEFINED_FONT_HANDLE;
+
+ g_free (entry);
+}
+
+/*
+ * FontFamilyEntry things
+ */
+static FontFamilyEntry*
+font_family_new (const char *family)
+{
+ FontFamilyEntry *entry;
+
+ g_return_val_if_fail (family != NULL, NULL);
+
+ entry = g_new (FontFamilyEntry, 1);
+
+ entry->family = g_strdup (family);
+ entry->fonts = NULL;
+
+ return entry;
+}
+
+static void
+free_font_entry (gpointer data, gpointer user_data)
+{
+ font_entry_free ((FontEntry*) data);
+}
+
+static void
+font_family_free (FontFamilyEntry* entry)
+{
+ g_return_if_fail (entry != NULL);
+
+ g_free (entry->family);
+
+ nautilus_g_list_free_deep_custom (entry->fonts, free_font_entry, NULL);
+ entry->fonts = NULL;
+
+ g_free (entry);
+}
+
+static void
+font_family_insert_font (FontFamilyEntry *family_entry, FontEntry *font_entry)
+{
+ g_return_if_fail (family_entry != NULL);
+ g_return_if_fail (font_entry != NULL);
+
+ family_entry->fonts = g_list_append (family_entry->fonts, (gpointer) font_entry);
+}
+
+#define EQUAL 0
+#define NOT_EQUAL 1
+
+static gint
+font_compare (gconstpointer a, gconstpointer b)
+{
+ FontEntry *font_entry_a = (FontEntry *) a;
+ FontEntry *font_entry_b = (FontEntry *) b;
+
+ g_return_val_if_fail (font_entry_a != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_b != NULL, NOT_EQUAL);
+
+ g_return_val_if_fail (font_entry_a->weight != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_a->slant != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_a->set_width != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_b->weight != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_b->slant != NULL, NOT_EQUAL);
+ g_return_val_if_fail (font_entry_b->set_width != NULL, NOT_EQUAL);
+
+ return (nautilus_str_is_equal (font_entry_a->weight, font_entry_b->weight)
+ && nautilus_str_is_equal (font_entry_a->slant, font_entry_b->slant)
+ && nautilus_str_is_equal (font_entry_a->set_width, font_entry_b->set_width)) ? EQUAL : NOT_EQUAL;
+}
+
+static FontEntry*
+font_family_find_font (const FontFamilyEntry *family_entry,
+ const char *weight,
+ const char *slant,
+ const char *set_width)
+{
+ FontEntry fake_font_entry;
+
+ GList *node;
+
+ g_return_val_if_fail (family_entry != NULL, NULL);
+ g_return_val_if_fail (weight != NULL, NULL);
+ g_return_val_if_fail (slant != NULL, NULL);
+ g_return_val_if_fail (set_width != NULL, NULL);
+
+ fake_font_entry.weight = (char *) weight;
+ fake_font_entry.slant = (char *) slant;
+ fake_font_entry.set_width = (char *) set_width;
+
+ node = g_list_find_custom (family_entry->fonts, &fake_font_entry, font_compare);
+
+ return node ? node->data : NULL;
+}
+
+static FontFamilyEntry *
+font_family_lookup (GHashTable *font_family_table, const char *family)
+{
+ gpointer value;
+
+ g_return_val_if_fail (font_family_table != NULL, NULL);
+ g_return_val_if_fail (family != NULL, NULL);
+
+ value = g_hash_table_lookup (font_family_table, (gconstpointer) family);
+
+ return (FontFamilyEntry *) value;
+}
+
+static FontFamilyEntry *
+font_family_lookup_with_insertion (GHashTable *font_family_table, const char *family)
+{
+ FontFamilyEntry *entry;
+
+ g_return_val_if_fail (font_family_table != NULL, NULL);
+ g_return_val_if_fail (family != NULL, NULL);
+
+ entry = g_hash_table_lookup (font_family_table, (gconstpointer) family);
+
+ if (entry == NULL) {
+
+ entry = font_family_new (family);
+
+ g_hash_table_insert (font_family_table, entry->family, entry);
+ }
+
+ return entry;
+}
+
+static void
+font_family_table_add_fonts (GHashTable *font_family_table, const char *font_path)
+{
+ NautilusStringList *font_pfb_list = NULL;
+ NautilusStringList *font_xfld_list = NULL;
+ guint i;
+
+ g_return_if_fail (font_family_table != NULL);
+ g_return_if_fail (font_path != NULL);
+ g_return_if_fail (g_file_exists (font_path));
+
+ if (!parse_font_description_file (font_path, &font_pfb_list, &font_xfld_list)) {
+ g_warning ("Dude, could not find no stikin fonts in %s", font_path);
+ return;
+ }
+
+ if (nautilus_string_list_get_length (font_pfb_list) != nautilus_string_list_get_length (font_xfld_list)) {
+ g_warning ("Dude, something got fucked");
+ return;
+ }
+
+ for (i = 0; i < nautilus_string_list_get_length (font_pfb_list); i++) {
+ NautilusStringList *tokenized_xfld;
+ char *path;
+ char *xfld;
+
+ char *foundry;
+ char *family;
+ char *weight;
+ char *slant;
+ char *set_width;
+
+ FontFamilyEntry *family_entry;
+ FontEntry *font_entry;
+
+ path = nautilus_string_list_nth (font_pfb_list, i);
+ g_assert (path != NULL);
+
+ xfld = nautilus_string_list_nth (font_xfld_list, i);
+ g_assert (xfld != NULL);
+
+ tokenized_xfld = nautilus_string_list_new_from_tokens (xfld, "-");
+
+ foundry = nautilus_string_list_nth (tokenized_xfld, 1);
+ family = nautilus_string_list_nth (tokenized_xfld, 2);
+ weight = nautilus_string_list_nth (tokenized_xfld, 3);
+ slant = nautilus_string_list_nth (tokenized_xfld, 4);
+ set_width = nautilus_string_list_nth (tokenized_xfld, 5);
+
+ family_entry = font_family_lookup_with_insertion (font_family_table, family);
+ g_assert (family_entry != NULL);
+
+ font_entry = font_family_find_font (family_entry, weight, slant, set_width);
+
+ if (font_entry != NULL) {
+ g_warning ("Dude, the font '%s-%s-%s-%s' already exists", family, weight, slant, set_width);
+ }
+ else {
+ font_entry = font_entry_new (weight, slant, set_width, path);
+
+ font_family_insert_font (family_entry, font_entry);
+ }
+
+ nautilus_string_list_free (tokenized_xfld);
+ g_free (foundry);
+ g_free (family);
+ g_free (weight);
+ g_free (slant);
+ g_free (set_width);
+
+ g_free (path);
+ g_free (xfld);
+ }
+
+ nautilus_string_list_free (font_pfb_list);
+ nautilus_string_list_free (font_xfld_list);
+}
+
+/* Public NautilusScalableFont methods */
+GtkObject*
+nautilus_scalable_font_new (const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width)
+{
+ /* const char *foundry = "URW"; */
+ FontFamilyEntry *family_entry;
+ FontEntry *font_entry;
+ NautilusScalableFont *font;
+
+ initialize_global_stuff_if_needed ();
+
+ family_entry = font_family_lookup (global_font_family_table, family);
+
+ if (family_entry == NULL) {
+ g_warning ("There is no such font: %s", family);
+ return NULL;
+ }
+
+ weight = weight ? weight : "medium";
+ slant = slant ? slant : "r";
+ set_width = set_width ? set_width : "normal";
+
+ font_entry = font_family_find_font (family_entry, weight, slant, set_width);
+
+ if (font_entry == NULL) {
+ g_warning ("There is no such font '%s-%s-%s-%s'", family, weight, slant, set_width);
+ return NULL;
+ }
+
+ /* 'Intern' the rsvg font handle if needed */
+ if (font_entry->font_handle == UNDEFINED_FONT_HANDLE) {
+ font_entry->font_handle = rsvg_ft_intern (global_rsvg_ft_context, font_entry->path);
+
+ }
+
+#if 0
+ g_print ("%s (%s, %s, %s %s) handle = %d\n" ,
+ __FUNCTION__, family, weight, slant, set_width, font_entry->font_handle);
+#endif
+
+ font = NAUTILUS_SCALABLE_FONT (gtk_type_new (nautilus_scalable_font_get_type ()));
+
+ font->detail->font_handle = font_entry->font_handle;
+
+ return GTK_OBJECT (font);
+}
+
+void
+nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text,
+ guint *text_width_out,
+ guint *text_height_out)
+{
+ RsvgFTGlyph *glyph;
+ double affine[6];
+ int glyph_xy[2];
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (text_width_out != NULL);
+ g_return_if_fail (text_height_out != NULL);
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+
+ *text_width_out = 0;
+ *text_height_out = 0;
+
+ if (text == NULL) {
+ return;
+ }
+
+ art_affine_identity (affine);
+
+ /* FIXME: We need to change rsvg_ft_render_string() to accept
+ * a 'do_render' flag so that we can use to to compute metrics
+ * without actually having to render
+ */
+ glyph = rsvg_ft_render_string (global_rsvg_ft_context,
+ font->detail->font_handle,
+ text,
+ font_width,
+ font_height,
+ affine,
+ glyph_xy);
+
+ *text_width_out = glyph->width;
+ *text_height_out = glyph->height;
+
+ rsvg_ft_glyph_unref (glyph);
+}
+
+void
+nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ guint num_text_lines,
+ guint text_line_widths[],
+ guint text_line_heights[],
+ guint *max_width_out,
+ guint *total_height_out)
+{
+ guint i;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text_lines != NULL);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (num_text_lines > 0);
+
+ if (max_width_out != NULL) {
+ *max_width_out = 0;
+ }
+
+ if (total_height_out != NULL) {
+ *total_height_out = 0;
+ }
+
+ for (i = 0; i < num_text_lines; i++) {
+ g_assert (text_lines[i] != NULL);
+ g_assert (text_line_widths[i] > 0);
+ g_assert (text_line_heights[i] > 0);
+
+ nautilus_scalable_font_measure_text (font,
+ font_width,
+ font_height,
+ text_lines[i],
+ &text_line_widths[i],
+ &text_line_heights[i]);
+
+ if (total_height_out != NULL) {
+ *total_height_out += text_line_heights[i];
+ }
+
+ if ((max_width_out != NULL) && (text_line_widths[i] > *max_width_out)) {
+ *max_width_out = text_line_widths[i];
+ }
+ }
+}
+
+guint
+nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,
+ const char *text,
+ guint available_width,
+ const guint font_sizes[],
+ guint num_font_sizes)
+{
+ NautilusStringList *tokenized_string;
+ guint i;
+ char *longest_string;
+
+ g_return_val_if_fail (NAUTILUS_IS_SCALABLE_FONT (font), 0);
+ g_return_val_if_fail (font_sizes != NULL, 0);
+ g_return_val_if_fail (num_font_sizes > 0, 0);
+
+ if (text == NULL || available_width < 1) {
+ return font_sizes[num_font_sizes - 1];
+ }
+
+ tokenized_string = nautilus_string_list_new_from_tokens (text, "\n");
+ longest_string = nautilus_string_list_get_longest_string (tokenized_string);
+ g_assert (longest_string != NULL);
+ nautilus_string_list_free (tokenized_string);
+
+ for (i = 0; i < num_font_sizes; i++) {
+ guint text_width;
+ guint text_height;
+
+ nautilus_scalable_font_measure_text (font,
+ font_sizes[i],
+ font_sizes[i],
+ longest_string,
+ &text_width,
+ &text_height);
+
+ if (text_width <= available_width) {
+ g_free (longest_string);
+ return font_sizes[i];
+ }
+ }
+
+ g_free (longest_string);
+
+ return font_sizes[num_font_sizes - 1];
+}
+
+void
+nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_area,
+ guint font_width,
+ guint font_height,
+ const char *text,
+ guint32 color,
+ guchar overall_alpha)
+{
+ RsvgFTGlyph *glyph;
+ double affine[6];
+ int glyph_xy[2];
+
+ guint pixbuf_width;
+ guint pixbuf_height;
+ guint pixbuf_rowstride;
+ guchar *pixbuf_pixels;
+
+ ArtRender *art_render;
+ ArtPixMaxDepth art_color_array[3];
+
+ ArtIRect area;
+ ArtIRect glyph_area;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (destination_pixbuf != NULL);
+ g_return_if_fail (destination_area != NULL);
+ g_return_if_fail (destination_area->x1 > destination_area->x0);
+ g_return_if_fail (destination_area->y1 > destination_area->y0);
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+
+ if (text == NULL) {
+ return;
+ }
+
+ art_affine_identity (affine);
+
+ glyph = rsvg_ft_render_string (global_rsvg_ft_context,
+ font->detail->font_handle,
+ text,
+ font_width,
+ font_height,
+ affine,
+ glyph_xy);
+
+ pixbuf_width = gdk_pixbuf_get_width (destination_pixbuf);
+ pixbuf_height = gdk_pixbuf_get_height (destination_pixbuf);
+ pixbuf_rowstride = gdk_pixbuf_get_rowstride (destination_pixbuf);
+ pixbuf_pixels = gdk_pixbuf_get_pixels (destination_pixbuf);
+
+ glyph_xy[0] = 0;
+ glyph_xy[1] = 0;
+
+ art_render = art_render_new (0,
+ 0,
+ pixbuf_width,
+ pixbuf_height,
+ pixbuf_pixels,
+ pixbuf_rowstride,
+ 3,
+ 8,
+ ART_ALPHA_SEPARATE,
+ NULL);
+
+ art_color_array[0] = ART_PIX_MAX_FROM_8 (NAUTILUS_RGBA_COLOR_GET_R (color));
+ art_color_array[1] = ART_PIX_MAX_FROM_8 (NAUTILUS_RGBA_COLOR_GET_G (color));
+ art_color_array[2] = ART_PIX_MAX_FROM_8 (NAUTILUS_RGBA_COLOR_GET_B (color));
+
+ art_render_image_solid (art_render, art_color_array);
+
+ glyph_area.x0 = glyph_xy[0] + destination_area->x0;
+ glyph_area.y0 = glyph_xy[1] + destination_area->y0;
+
+ glyph_area.x1 = glyph_area.x0 + glyph->width;
+ glyph_area.y1 = glyph_area.y0 + glyph->height;
+
+ art_irect_union (&area, &glyph_area, destination_area);
+
+/* glyph_xy[0] += destination_point->x; */
+/* glyph_xy[1] += destination_point->y; */
+
+ art_render_mask (art_render,
+ glyph_area.x0,
+ glyph_area.y0,
+ glyph_area.x1,
+ glyph_area.y1,
+ glyph->buf,
+ glyph->rowstride);
+
+ art_render_invoke (art_render);
+
+ rsvg_ft_glyph_unref (glyph);
+}
+
+void
+nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_area,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ const guint text_line_widths[],
+ const guint text_line_heights[],
+ GtkJustification justification,
+ const guint num_text_lines,
+ guint line_offset,
+ guint32 color,
+ guchar overall_alpha)
+{
+ guint i;
+
+ gint x;
+ gint y;
+
+ guint available_width;
+ guint available_height;
+
+ g_return_if_fail (NAUTILUS_IS_SCALABLE_FONT (font));
+ g_return_if_fail (destination_pixbuf != NULL);
+ g_return_if_fail (destination_area != NULL);
+ g_return_if_fail (font_width > 0);
+ g_return_if_fail (font_height > 0);
+ g_return_if_fail (text_lines != NULL);
+ g_return_if_fail (text_line_widths != NULL);
+ g_return_if_fail (text_line_heights != NULL);
+ g_return_if_fail (num_text_lines > 0);
+ g_return_if_fail (justification >= GTK_JUSTIFY_LEFT && justification <= GTK_JUSTIFY_FILL);
+ g_return_if_fail (destination_area->x1 > destination_area->x0);
+ g_return_if_fail (destination_area->y1 > destination_area->y0);
+
+ x = destination_area->x0;
+ y = destination_area->y0;
+
+ available_width = destination_area->x1 - destination_area->x0;
+ available_height = destination_area->y1 - destination_area->y0;
+
+ for (i = 0; i < num_text_lines; i++) {
+ ArtIRect area;
+
+ g_assert (text_lines[i] != NULL);
+ g_assert (text_line_widths[i] > 0);
+ g_assert (text_line_heights[i] > 0);
+
+ switch (justification) {
+ case GTK_JUSTIFY_LEFT:
+ area.x0 = x;
+ break;
+
+ case GTK_JUSTIFY_CENTER:
+ case GTK_JUSTIFY_FILL:
+ if (text_line_widths[i] <= available_width) {
+ area.x0 = x + ((available_width - text_line_widths[i]) / 2);
+ }
+ else {
+ area.x0 = x - ((text_line_widths[i] - available_width) / 2);
+ }
+ break;
+
+ case GTK_JUSTIFY_RIGHT:
+ area.x0 = x + available_width - text_line_widths[i];
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ area.y0 = y;
+
+ nautilus_scalable_font_draw_text (font,
+ destination_pixbuf,
+ &area,
+ font_width,
+ font_height,
+ text_lines[i],
+ color,
+ overall_alpha);
+
+ y += (line_offset + text_line_heights[i]);
+ }
+}
+
+static void
+default_font_at_exit_destructor (void)
+{
+ if (global_default_font != NULL) {
+ gtk_object_unref (GTK_OBJECT (global_default_font));
+ global_default_font = NULL;
+ }
+}
+
+NautilusScalableFont *
+nautilus_scalable_font_get_default_font (void)
+{
+ if (global_default_font == NULL) {
+ global_default_font = NAUTILUS_SCALABLE_FONT (nautilus_scalable_font_new ("Nimbus Sans L", NULL, NULL, NULL));
+ g_assert (global_default_font != NULL);
+ g_atexit (default_font_at_exit_destructor);
+ }
+
+ gtk_object_ref (GTK_OBJECT (global_default_font));
+
+ return global_default_font;
+}
+
+static void
+font_family_table_for_each_append (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ NautilusStringList *list = (NautilusStringList *) user_data;
+ FontFamilyEntry *family_entry = (FontFamilyEntry *) value;
+
+ g_assert (family_entry != NULL);
+ g_assert (!nautilus_string_list_contains (list, family_entry->family));
+
+ nautilus_string_list_insert (list, family_entry->family);
+}
+
+static void
+font_family_table_for_each_free (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ FontFamilyEntry *family_entry = (FontFamilyEntry *) value;
+ g_assert (family_entry != NULL);
+
+ font_family_free (family_entry);
+}
+
+static NautilusStringList *
+font_family_table_get_family_list (GHashTable *font_family_table)
+{
+ NautilusStringList *list;
+
+ g_return_val_if_fail (font_family_table != NULL, NULL);
+
+ list = nautilus_string_list_new ();
+
+ g_hash_table_foreach (font_family_table, font_family_table_for_each_append, list);
+
+ return list;
+}
+
+NautilusStringList *
+nautilus_scalable_font_get_font_family_list (void)
+{
+ initialize_global_stuff_if_needed ();
+
+ return font_family_table_get_family_list (global_font_family_table);
+}
+
+static void
+font_family_table_free (GHashTable *font_family_table)
+{
+ g_assert (font_family_table != NULL);
+
+ g_hash_table_foreach (font_family_table, font_family_table_for_each_free, NULL);
+
+ g_hash_table_destroy (font_family_table);
+}
+
+static void
+font_family_table_at_exit_destructor (void)
+{
+ if (global_font_family_table != NULL) {
+ font_family_table_free (global_font_family_table);
+ global_font_family_table = NULL;
+ }
+}
+
+gboolean
+nautilus_scalable_font_query_font (const char *family,
+ NautilusStringList **weights_out,
+ NautilusStringList **slants_out,
+ NautilusStringList **set_widths_out)
+{
+ FontFamilyEntry *family_entry;
+ GList *iterator;
+
+ g_return_val_if_fail (family != NULL, FALSE);
+
+ if (weights_out != NULL) {
+ *weights_out = NULL;
+ }
+
+ if (slants_out != NULL) {
+ *slants_out = NULL;
+ }
+
+ if (set_widths_out != NULL) {
+ *set_widths_out = NULL;
+ }
+
+ family_entry = font_family_lookup (global_font_family_table, family);
+
+ if (family_entry == NULL) {
+ return FALSE;
+ }
+
+ if (weights_out == NULL && slants_out == NULL && set_widths_out == NULL) {
+ return TRUE;
+ }
+
+ if (weights_out != NULL) {
+ *weights_out = nautilus_string_list_new ();
+ }
+
+ if (slants_out != NULL) {
+ *slants_out = nautilus_string_list_new ();
+ }
+
+ if (set_widths_out != NULL) {
+ *set_widths_out = nautilus_string_list_new ();
+ }
+
+ for (iterator = family_entry->fonts; iterator != NULL; iterator = iterator->next) {
+ FontEntry *font_entry = (FontEntry *) iterator->data;
+ g_assert (font_entry != NULL);
+
+ if (weights_out != NULL) {
+ nautilus_string_list_insert (*weights_out, font_entry->weight);
+ }
+
+ if (slants_out != NULL) {
+ nautilus_string_list_insert (*slants_out, font_entry->slant);
+ }
+
+ if (set_widths_out != NULL) {
+ nautilus_string_list_insert (*set_widths_out, font_entry->set_width);
+ }
+ }
+
+ return TRUE;
+}
+
+#if 0
+static const char * global_default_font_path[] =
+{
+ "/usr/lib/X11/fonts/Type1",
+ "/usr/share/fonts/default/Type1"
+};
+#endif
+
+static void
+initialize_global_stuff_if_needed (void)
+{
+ static gboolean fonts_initialized = FALSE;
+
+ /* Initialize the rsvg font context shared by all fonts */
+ if (global_rsvg_ft_context == NULL) {
+ global_rsvg_ft_context = rsvg_ft_ctx_new ();
+ }
+
+ /* Initialize the global font table */
+ if (fonts_initialized == FALSE) {
+ fonts_initialized = TRUE;
+ global_font_family_table = g_hash_table_new (g_str_hash, g_str_equal);
+ font_family_table_add_fonts (global_font_family_table, "/usr/share/fonts/default/Type1");
+
+ g_atexit (font_family_table_at_exit_destructor);
+ }
+}
diff --git a/libnautilus-private/nautilus-scalable-font.h b/libnautilus-private/nautilus-scalable-font.h
new file mode 100644
index 000000000..f640e9b45
--- /dev/null
+++ b/libnautilus-private/nautilus-scalable-font.h
@@ -0,0 +1,138 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/* nautilus-scalable-font.h - A GtkObject subclass for access to scalable fonts.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Authors: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+
+/* NautilusScalableFont is a GtkObject that provdes a simple
+ * interface to Raph Levien's librsvg FreeType2 bases anti aliased
+ * text rendering.
+ *
+ * Currently, Type1 only Type1 fonts are supported.
+ *
+ * Fonts are automatically queried and used if available. Right
+ * now this is fairly simple code which does not handle all the
+ * complexities of the hell that is x fonts.
+ *
+ * In the Star Trek future, we will use gnome-print (gnome-font?).
+ * However, we will keep the interface to scalable font usage simple
+ * and hidden behind this interface.
+ *
+ */
+
+#ifndef NAUTILUS_SCALABLE_FONT_H
+#define NAUTILUS_SCALABLE_FONT_H
+
+#include <gtk/gtkobject.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <libgnome/gnome-defs.h>
+#include <libnautilus-extensions/nautilus-string-list.h>
+#include <libart_lgpl/art_rect.h>
+
+BEGIN_GNOME_DECLS
+
+#define NAUTILUS_TYPE_SCALABLE_FONT (nautilus_scalable_font_get_type ())
+#define NAUTILUS_SCALABLE_FONT(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_SCALABLE_FONT, NautilusScalableFont))
+#define NAUTILUS_SCALABLE_FONT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_SCALABLE_FONT, NautilusScalableFontClass))
+#define NAUTILUS_IS_SCALABLE_FONT(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_SCALABLE_FONT))
+#define NAUTILUS_IS_SCALABLE_FONT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_SCALABLE_FONT))
+
+typedef struct _NautilusScalableFont NautilusScalableFont;
+typedef struct _NautilusScalableFontClass NautilusScalableFontClass;
+typedef struct _NautilusScalableFontDetail NautilusScalableFontDetail;
+
+struct _NautilusScalableFont
+{
+ /* Superclass */
+ GtkObject object;
+
+ /* Private things */
+ NautilusScalableFontDetail *detail;
+};
+
+struct _NautilusScalableFontClass
+{
+ GtkObjectClass parent_class;
+};
+
+GtkType nautilus_scalable_font_get_type (void);
+GtkObject * nautilus_scalable_font_new (const char *family,
+ const char *weight,
+ const char *slant,
+ const char *set_width);
+void nautilus_scalable_font_measure_text (const NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text,
+ guint *text_width_out,
+ guint *text_height_out);
+void nautilus_scalable_font_measure_text_lines (NautilusScalableFont *font,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ guint num_text_lines,
+ guint text_line_widths[],
+ guint text_line_heights[],
+ guint *max_width_out,
+ guint *total_height_out);
+void nautilus_scalable_font_draw_text (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_area,
+ guint font_width,
+ guint font_height,
+ const char *text,
+ guint32 color,
+ guchar overall_alpha);
+void nautilus_scalable_font_draw_text_lines (const NautilusScalableFont *font,
+ GdkPixbuf *destination_pixbuf,
+ const ArtIRect *destination_area,
+ guint font_width,
+ guint font_height,
+ const char *text_lines[],
+ const guint text_line_widths[],
+ const guint text_line_heights[],
+ GtkJustification justification,
+ const guint num_lines,
+ guint line_offset,
+ guint32 color,
+ guchar overall_alpha);
+guint nautilus_scalable_font_largest_fitting_font_size (const NautilusScalableFont *font,
+ const char *text,
+ guint available_width,
+ const guint font_sizes[],
+ guint num_font_sizes);
+NautilusScalableFont *nautilus_scalable_font_get_default_font (void);
+NautilusStringList * nautilus_scalable_font_get_font_family_list (void);
+gboolean nautilus_scalable_font_query_font (const char *family,
+ NautilusStringList **weights,
+ NautilusStringList **slants,
+ NautilusStringList **set_widths);
+gboolean nautilus_scalable_font_query_font (const char *family,
+ NautilusStringList **weights,
+ NautilusStringList **slants,
+ NautilusStringList **set_widths);
+
+END_GNOME_DECLS
+
+#endif /* NAUTILUS_SCALABLE_FONT_H */
+
+
diff --git a/libnautilus-private/nautilus-string-map.c b/libnautilus-private/nautilus-string-map.c
new file mode 100644
index 000000000..e93c9b052
--- /dev/null
+++ b/libnautilus-private/nautilus-string-map.c
@@ -0,0 +1,295 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-string-list.h: A collection of strings.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#include <config.h>
+
+#include "nautilus-string-map.h"
+#include "nautilus-string-list.h"
+#include "nautilus-string.h"
+#include "nautilus-glib-extensions.h"
+#include "nautilus-lib-self-check-functions.h"
+#include <string.h>
+
+/* FIXME: The case sensitive flag is not functional yet. Need to change
+ * NautilusStringList to also accept a case_sensitive flag to make it work.
+ */
+
+struct _NautilusStringMap
+{
+ GList *map;
+ gboolean case_sensitive;
+};
+
+typedef struct
+{
+ char *string;
+ NautilusStringList *map_list;
+} MapEntry;
+
+/* MapEntry things */
+static MapEntry *map_entry_new (const char *string);
+static void map_entry_free (MapEntry *map_entry);
+static MapEntry *map_entry_list_lookup_mapped_string (GList *entry_list,
+ const char *mapped_string);
+static MapEntry *map_entry_list_lookup (GList *entry_list,
+ const char *string);
+
+/**
+ * nautilus_string_map_new:
+ *
+ * @case_sensitive: Boolean flag indicating whether the string map is case sensitive.
+ *
+ * Allocate an empty string map.
+ *
+ * Return value: A newly allocated string map.
+ */
+NautilusStringMap *
+nautilus_string_map_new (gboolean case_sensitive)
+{
+ NautilusStringMap * string_map;
+
+ string_map = g_new (NautilusStringMap, 1);
+
+ string_map->map = NULL;
+ string_map->case_sensitive = case_sensitive;
+
+ return string_map;
+}
+
+/**
+ * nautilus_string_map_free:
+ *
+ * @string_map: A NautilusStringMap
+ *
+ * Free the string map.
+ */
+void
+nautilus_string_map_free (NautilusStringMap *string_map)
+{
+ if (string_map == NULL) {
+ return;
+ }
+
+ nautilus_string_map_clear (string_map);
+
+ g_free (string_map);
+}
+
+static void
+map_for_each_node_free (gpointer data,
+ gpointer user_data)
+{
+ MapEntry *map_entry = (MapEntry *) data;
+ g_assert (map_entry != NULL);
+
+ map_entry_free (map_entry);
+}
+
+/**
+ * nautilus_string_map_clear:
+ *
+ * @string_map: A NautilusStringMap
+ *
+ * Clear the string map.
+ */
+void
+nautilus_string_map_clear (NautilusStringMap *string_map)
+{
+ if (string_map == NULL) {
+ return;
+ }
+
+ g_return_if_fail (string_map != NULL);
+
+ nautilus_g_list_free_deep_custom (string_map->map, map_for_each_node_free, NULL);
+
+ string_map->map = NULL;
+}
+
+/**
+ * nautilus_string_map_lookup:
+ *
+ * @string_map: A NautilusStringMap
+ * @string: The mapped string to lookup
+ *
+ * Lookup the mapping for 'string'
+ *
+ * Return value: A copy of the mapped_to_string or NULL if no mapping exists.
+ */
+char *
+nautilus_string_map_lookup (const NautilusStringMap *string_map,
+ const char *string)
+{
+ MapEntry *map_entry;
+
+ if (string_map == NULL || string == NULL) {
+ return NULL;
+ }
+
+ map_entry = map_entry_list_lookup (string_map->map, string);
+
+ return map_entry ? g_strdup (map_entry->string) : NULL;
+}
+
+/**
+ * nautilus_string_map_add:
+ *
+ * @string_map: A NautilusStringMap
+ *
+ * Add a mapping from 'string' to 'strings_maps_to'
+ */
+void
+nautilus_string_map_add (NautilusStringMap *string_map,
+ const char *string_maps_to,
+ const char *string)
+{
+ MapEntry *map_entry;
+
+ g_return_if_fail (string_map != NULL);
+ g_return_if_fail (string_maps_to != NULL);
+ g_return_if_fail (string != NULL);
+
+ map_entry = map_entry_list_lookup_mapped_string (string_map->map, string_maps_to);
+
+ if (map_entry == NULL) {
+ map_entry = map_entry_new (string_maps_to);
+
+ /* Add a mapping for the string_maps_to to simplify things */
+ nautilus_string_list_insert (map_entry->map_list, string_maps_to);
+
+ string_map->map = g_list_append (string_map->map, map_entry);
+ }
+
+ nautilus_string_list_insert (map_entry->map_list, string);
+}
+
+/* MapEntry things */
+static MapEntry *
+map_entry_new (const char *string)
+{
+ MapEntry *map_entry;
+
+ g_return_val_if_fail (string != NULL, NULL);
+
+ map_entry = g_new (MapEntry, 1);
+ map_entry->map_list = nautilus_string_list_new ();
+ map_entry->string = g_strdup (string);
+
+ return map_entry;
+}
+
+static void
+map_entry_free (MapEntry *map_entry)
+{
+ g_return_if_fail (map_entry);
+
+ nautilus_string_list_free (map_entry->map_list);
+ map_entry->map_list = NULL;
+ g_free (map_entry->string);
+ g_free (map_entry);
+}
+
+static MapEntry *
+map_entry_list_lookup_mapped_string (GList *entry_list,
+ const char *mapped_string)
+{
+ GList *iterator;
+
+ g_return_val_if_fail (mapped_string != NULL, NULL);
+
+ if (entry_list == NULL) {
+ return NULL;
+ }
+
+ for (iterator = entry_list; iterator != NULL; iterator = iterator->next) {
+ MapEntry *map_entry = (MapEntry *) iterator->data;
+ g_assert (map_entry != NULL);
+
+ if (nautilus_str_is_equal (map_entry->string, mapped_string)) {
+ return map_entry;
+ }
+ }
+
+ return NULL;
+}
+
+static MapEntry *
+map_entry_list_lookup (GList *entry_list,
+ const char *string)
+{
+ GList *iterator;
+
+ g_return_val_if_fail (string != NULL, NULL);
+
+ if (entry_list == NULL) {
+ return NULL;
+ }
+
+ for (iterator = entry_list; iterator != NULL; iterator = iterator->next) {
+ MapEntry *map_entry = (MapEntry *) iterator->data;
+ g_assert (map_entry != NULL);
+
+ if (nautilus_string_list_contains (map_entry->map_list, string)) {
+ return map_entry;
+ }
+ }
+
+ return NULL;
+}
+
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
+
+void
+nautilus_self_check_string_map (void)
+{
+#if 0
+ NautilusStringMap *map;
+
+ map = nautilus_string_map_new (TRUE);
+
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "foo"), NULL);
+
+ nautilus_string_map_clear (map);
+
+ nautilus_string_map_add (map, "animal", "dog");
+ nautilus_string_map_add (map, "animal", "cat");
+ nautilus_string_map_add (map, "animal", "mouse");
+ nautilus_string_map_add (map, "human", "geek");
+ nautilus_string_map_add (map, "human", "nerd");
+ nautilus_string_map_add (map, "human", "lozer");
+
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "animal"), "animal");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "cat"), "animal");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "dog"), "animal");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "mouse"), "animal");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "human"), "human");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "geek"), "human");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "nerd"), "human");
+ NAUTILUS_CHECK_STRING_RESULT (nautilus_string_map_lookup (map, "lozer"), "human");
+
+ nautilus_string_map_free (map);
+#endif
+}
+
+#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/libnautilus-private/nautilus-string-map.h b/libnautilus-private/nautilus-string-map.h
new file mode 100644
index 000000000..71b5820e9
--- /dev/null
+++ b/libnautilus-private/nautilus-string-map.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-string-list.h: A collection of strings.
+
+ Copyright (C) 1999, 2000 Eazel, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Ramiro Estrugo <ramiro@eazel.com>
+*/
+
+#ifndef NAUTILUS_STRING_MAP_H
+#define NAUTILUS_STRING_MAP_H
+
+#include <glib.h>
+
+/* Opaque type declaration. */
+typedef struct _NautilusStringMap NautilusStringMap;
+
+/* Construct an empty string list. */
+NautilusStringMap *nautilus_string_map_new (gboolean case_sensitive);
+
+/* Construct a string list with a single element */
+void nautilus_string_map_add (NautilusStringMap *string_map,
+ const char *string_maps_to,
+ const char *string);
+void nautilus_string_map_free (NautilusStringMap *string_map);
+void nautilus_string_map_clear (NautilusStringMap *string_map);
+char * nautilus_string_map_lookup (const NautilusStringMap *string_map,
+ const char *key);
+
+#endif /* NAUTILUS_STRING_MAP_H */
+
diff --git a/test/.cvsignore b/test/.cvsignore
index d0e86c6d2..d3cfac69f 100644
--- a/test/.cvsignore
+++ b/test/.cvsignore
@@ -4,10 +4,13 @@
*.lo
Makefile
Makefile.in
+test-nautilus-font
+test-nautilus-font-picker
test-nautilus-image
-test-nautilus-graphic
+test-nautilus-label
test-nautilus-mime-actions
test-nautilus-mime-actions-set
test-nautilus-password-dialog
test-nautilus-preferences
test-nautilus-widgets
+font_test.png
diff --git a/test/Makefile.am b/test/Makefile.am
index a7700ad61..9ae10a6f0 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -12,6 +12,7 @@ INCLUDES =\
$(XML_CFLAGS) \
-DVERSION="\"$(VERSION)\"" \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+ -DNAUTILUS_DATADIR=\""$(datadir)/nautilus"\" \
$(NULL)
LDADD =\
@@ -26,7 +27,10 @@ LDADD =\
$(NULL)
noinst_PROGRAMS =\
+ test-nautilus-font \
+ test-nautilus-font-picker \
test-nautilus-image \
+ test-nautilus-label \
test-nautilus-mime-actions \
test-nautilus-mime-actions-set \
test-nautilus-password-dialog \
@@ -34,18 +38,12 @@ noinst_PROGRAMS =\
test-nautilus-widgets \
$(NULL)
+test_nautilus_font_SOURCES = test-nautilus-font.c
+test_nautilus_font_picker_SOURCES = test-nautilus-font-picker.c
+test_nautilus_image_SOURCES = test-nautilus-image.c
+test_nautilus_label_SOURCES = test-nautilus-label.c
test_nautilus_mime_actions_SOURCES = test-nautilus-mime-actions.c
-
test_nautilus_mime_actions_set_SOURCES = test-nautilus-mime-actions-set.c
-
-test_nautilus_widgets_SOURCES = test-nautilus-widgets.c
-
-test_nautilus_preferences_SOURCES = test-nautilus-preferences.c
-
-test_nautilus_image_SOURCES = test-nautilus-image.c
-
test_nautilus_password_dialog_SOURCES = test-nautilus-password-dialog.c
-
-EXTRA_DIST = \
- test-nautilus-mime-actions.c \
- $(NULL)
+test_nautilus_preferences_SOURCES = test-nautilus-preferences.c
+test_nautilus_widgets_SOURCES = test-nautilus-widgets.c
diff --git a/test/test-nautilus-font-picker.c b/test/test-nautilus-font-picker.c
new file mode 100644
index 000000000..cd1331912
--- /dev/null
+++ b/test/test-nautilus-font-picker.c
@@ -0,0 +1,55 @@
+
+#include <config.h>
+
+#include <libnautilus-extensions/nautilus-font-picker.h>
+
+#include <gtk/gtk.h>
+
+static void
+font_picker_changed_callback (GtkWidget *font_picker, gpointer user_data)
+{
+ char *family;
+ char *weight;
+ char *slant;
+ char *set_width;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+
+ family = nautilus_font_picker_get_selected_family (NAUTILUS_FONT_PICKER (font_picker));
+ weight = nautilus_font_picker_get_selected_weight (NAUTILUS_FONT_PICKER (font_picker));
+ slant = nautilus_font_picker_get_selected_slant (NAUTILUS_FONT_PICKER (font_picker));
+ set_width = nautilus_font_picker_get_selected_set_width (NAUTILUS_FONT_PICKER (font_picker));
+
+ g_print ("%s (%s,%s,%s,%s)\n", __FUNCTION__, family, weight, slant, set_width);
+
+ g_free (family);
+ g_free (weight);
+ g_free (slant);
+ g_free (set_width);
+}
+
+int
+main (int argc, char * argv[])
+{
+ GtkWidget *window;
+ GtkWidget *font_picker;
+
+ gnome_init ("foo", "bar", argc, argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ font_picker = nautilus_font_picker_new ();
+
+ gtk_container_add (GTK_CONTAINER (window), font_picker);
+
+ gtk_signal_connect (GTK_OBJECT (font_picker),
+ "selected_font_changed",
+ GTK_SIGNAL_FUNC (font_picker_changed_callback),
+ (gpointer) NULL);
+
+ gtk_widget_show (font_picker);
+ gtk_widget_show (window);
+ gtk_main ();
+
+ return 0;
+}
diff --git a/test/test-nautilus-font.c b/test/test-nautilus-font.c
new file mode 100644
index 000000000..5a212b084
--- /dev/null
+++ b/test/test-nautilus-font.c
@@ -0,0 +1,77 @@
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <libnautilus-extensions/nautilus-background.h>
+#include <libnautilus-extensions/nautilus-file-utilities.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
+#include <libnautilus-extensions/nautilus-glib-extensions.h>
+#include <libnautilus-extensions/nautilus-gdk-extensions.h>
+#include <libnautilus-extensions/nautilus-gtk-extensions.h>
+#include <libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h>
+#include <libnautilus-extensions/nautilus-icon-factory.h>
+#include <libnautilus-extensions/nautilus-string-list.h>
+#include <libnautilus-extensions/nautilus-string-picker.h>
+#include <libnautilus-extensions/nautilus-font-picker.h>
+#include <libnautilus-extensions/nautilus-text-caption.h>
+
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+#include <libnautilus-extensions/nautilus-label.h>
+#include <libnautilus-extensions/nautilus-image.h>
+
+int
+main (int argc, char* argv[])
+{
+ GdkPixbuf *pixbuf;
+ guint text_width;
+ guint text_height;
+ ArtIRect area;
+ NautilusScalableFont *font;
+
+ const char *text = "Something";
+ const guint font_width = 64;
+ const guint font_height = 64;
+
+ gtk_init (&argc, &argv);
+ gdk_rgb_init ();
+
+ font = NAUTILUS_SCALABLE_FONT (nautilus_scalable_font_new ("Nimbus Sans L", NULL, NULL, NULL));
+ g_assert (font != NULL);
+
+ nautilus_scalable_font_measure_text (font,
+ font_width,
+ font_height,
+ text,
+ &text_width,
+ &text_height);
+
+ g_print ("size of '%s' = (%d,%d)\n", text, text_width, text_height);
+
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 512, 256);
+ g_assert (pixbuf != NULL);
+
+ area.x0 = 0;
+ area.y0 = 0;
+
+ area.x1 = 512;
+ area.y1 = 256;
+
+ nautilus_scalable_font_draw_text (font,
+ pixbuf,
+ &area,
+ font_width,
+ font_height,
+ text,
+ NAUTILUS_RGB_COLOR_RED,
+ 255);
+
+ g_assert (pixbuf != NULL);
+
+ nautilus_gdk_pixbuf_save_to_file (pixbuf, "font_test.png");
+
+ g_print ("saving test png file to font_test.png\n");
+
+ gdk_pixbuf_unref (pixbuf);
+
+ return 0;
+}
diff --git a/test/test-nautilus-image.c b/test/test-nautilus-image.c
index 9773dec90..b45cb7510 100644
--- a/test/test-nautilus-image.c
+++ b/test/test-nautilus-image.c
@@ -2,356 +2,676 @@
#include <config.h>
#include <gtk/gtk.h>
-#include <libnautilus-extensions/nautilus-image.h>
-#include <libnautilus-extensions/nautilus-icon-factory.h>
+#include <libnautilus-extensions/nautilus-background.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-font-factory.h>
+#include <libnautilus-extensions/nautilus-glib-extensions.h>
+#include <libnautilus-extensions/nautilus-gdk-extensions.h>
+#include <libnautilus-extensions/nautilus-gtk-extensions.h>
+#include <libnautilus-extensions/nautilus-icon-factory.h>
+#include <libnautilus-extensions/nautilus-string-list.h>
+#include <libnautilus-extensions/nautilus-string-picker.h>
+#include <libnautilus-extensions/nautilus-font-picker.h>
+#include <libnautilus-extensions/nautilus-text-caption.h>
+#include <libnautilus-extensions/nautilus-string.h>
+#include <libgnomevfs/gnome-vfs-init.h>
+
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+#include <libnautilus-extensions/nautilus-label.h>
+#include <libnautilus-extensions/nautilus-image.h>
-static GdkPixbuf*
-create_background (void)
+static void
+red_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
{
- GdkPixbuf *background;
-
- background = gdk_pixbuf_new_from_file ("/gnome/share/nautilus/backgrounds/pale_coins.png");
+ NautilusLabel *label;
+ guint32 color;
- g_assert (background != NULL);
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- return background;
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
+
+ color = NAUTILUS_RGBA_COLOR_PACK ((guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_G (color),
+ NAUTILUS_RGBA_COLOR_GET_B (color),
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
}
-static GdkPixbuf*
-create_pixbuf (const char *name)
+static void
+green_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
{
- char *icon_path;
- GdkPixbuf *pixbuf = NULL;
+ NautilusLabel *label;
+ guint32 color;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- g_assert (name != NULL);
+ label = NAUTILUS_LABEL (client_data);
- icon_path = nautilus_pixmap_file (name);
- g_assert (icon_path != NULL);
+ color = nautilus_label_get_text_color (label);
- pixbuf = gdk_pixbuf_new_from_file (icon_path);
+ color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
+ (guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_B (color),
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
+}
- g_assert (pixbuf != NULL);
+static void
+blue_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+ guint32 color;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- g_free (icon_path);
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
- return pixbuf;
+ color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
+ NAUTILUS_RGBA_COLOR_GET_G (color),
+ (guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
}
-static GtkWidget*
-create_image (const char *name, GdkPixbuf *background)
+static void
+alpha_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
{
- GtkWidget *image;
- GdkPixbuf *pixbuf;
+ NautilusLabel *label;
- g_assert (background != NULL);
-
- image = nautilus_image_new ();
- g_assert (image != NULL);
-
- nautilus_image_set_background_type (NAUTILUS_IMAGE (image), NAUTILUS_IMAGE_BACKGROUND_PIXBUF);
- nautilus_image_set_background_pixbuf (NAUTILUS_IMAGE (image), background);
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- if (name != NULL)
- {
- pixbuf = create_pixbuf (name);
- g_assert (pixbuf != NULL);
-
- nautilus_image_set_pixbuf (NAUTILUS_IMAGE (image), pixbuf);
-
- gdk_pixbuf_unref (pixbuf);
- }
+ label = NAUTILUS_LABEL (client_data);
- return image;
+ nautilus_label_set_text_alpha (NAUTILUS_LABEL (label), (guchar) adjustment->value);
}
static void
-alpha_scale_value_changed (GtkAdjustment *adjustment, gpointer client_data)
+red_background_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
{
- GList *image_list;
+ NautilusLabel *label;
+ guint32 color;
g_return_if_fail (adjustment != NULL);
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- image_list = (GList *) client_data;
-
- while (image_list)
- {
- g_assert (image_list->data != NULL);
- g_assert (NAUTILUS_IS_IMAGE (image_list->data));
-
- nautilus_image_set_overall_alpha (NAUTILUS_IMAGE (image_list->data), (guchar) adjustment->value);
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
- image_list = image_list->next;
- }
+ color = NAUTILUS_RGBA_COLOR_PACK ((guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_G (color),
+ NAUTILUS_RGBA_COLOR_GET_B (color),
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
}
static void
-red_color_value_changed (GtkAdjustment *adjustment, gpointer client_data)
+green_background_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
{
- GList *image_list;
+ NautilusLabel *label;
+ guint32 color;
g_return_if_fail (adjustment != NULL);
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- image_list = (GList *) client_data;
-
- while (image_list)
- {
- NautilusImage *image;
- guint32 color;
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
- g_assert (image_list->data != NULL);
- g_assert (NAUTILUS_IS_IMAGE (image_list->data));
+ color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
+ (guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_B (color),
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
+}
- image = NAUTILUS_IMAGE (image_list->data);
+static void
+blue_background_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+ guint32 color;
- color = nautilus_image_get_background_color (image);
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- color = NAUTILUS_RGBA_COLOR_PACK ((guchar) adjustment->value,
- NAUTILUS_RGBA_COLOR_GET_G (color),
- NAUTILUS_RGBA_COLOR_GET_B (color),
- NAUTILUS_RGBA_COLOR_GET_A (color));
-
- nautilus_image_set_background_color (image, color);
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
- image_list = image_list->next;
- }
+ color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
+ NAUTILUS_RGBA_COLOR_GET_G (color),
+ (guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
}
static void
-green_color_value_changed (GtkAdjustment *adjustment, gpointer client_data)
+alpha_background_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
{
- GList *image_list;
+ NautilusLabel *label;
g_return_if_fail (adjustment != NULL);
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- image_list = (GList *) client_data;
-
- while (image_list)
- {
- NautilusImage *image;
- guint32 color;
+ label = NAUTILUS_LABEL (client_data);
- g_assert (image_list->data != NULL);
- g_assert (NAUTILUS_IS_IMAGE (image_list->data));
+ nautilus_label_set_text_alpha (NAUTILUS_LABEL (label), (guchar) adjustment->value);
+}
- image = NAUTILUS_IMAGE (image_list->data);
+static void
+font_size_changed_callback (NautilusStringPicker *string_picker, gpointer client_data)
+{
+ char *string;
+ int size;
- color = nautilus_image_get_background_color (image);
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
- (guchar) adjustment->value,
- NAUTILUS_RGBA_COLOR_GET_B (color),
- NAUTILUS_RGBA_COLOR_GET_A (color));
-
- nautilus_image_set_background_color (image, color);
+ string = nautilus_string_picker_get_selected_string (string_picker);
- image_list = image_list->next;
+ if (nautilus_eat_str_to_int (string, &size)) {
+ nautilus_label_set_font_size (NAUTILUS_LABEL (client_data), (guint) size);
}
+
+ g_free (string);
}
static void
-blue_color_value_changed (GtkAdjustment *adjustment, gpointer client_data)
+font_changed_callback (NautilusFontPicker *font_picker, gpointer client_data)
{
- GList *image_list;
-
- g_return_if_fail (adjustment != NULL);
- g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
- g_return_if_fail (client_data != NULL);
+ NautilusScalableFont *font;
+ char *family;
+ char *weight;
+ char *slant;
+ char *set_width;
- image_list = (GList *) client_data;
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- while (image_list)
- {
- NautilusImage *image;
- guint32 color;
+ family = nautilus_font_picker_get_selected_family (NAUTILUS_FONT_PICKER (font_picker));
+ weight = nautilus_font_picker_get_selected_weight (NAUTILUS_FONT_PICKER (font_picker));
+ slant = nautilus_font_picker_get_selected_slant (NAUTILUS_FONT_PICKER (font_picker));
+ set_width = nautilus_font_picker_get_selected_set_width (NAUTILUS_FONT_PICKER (font_picker));
- g_assert (image_list->data != NULL);
- g_assert (NAUTILUS_IS_IMAGE (image_list->data));
+ g_print ("%s (%s,%s,%s,%s)\n", __FUNCTION__, family, weight, slant, set_width);
- image = NAUTILUS_IMAGE (image_list->data);
+ font = NAUTILUS_SCALABLE_FONT (nautilus_scalable_font_new (family, weight, slant, set_width));
+ g_assert (font != NULL);
- color = nautilus_image_get_background_color (image);
+ nautilus_label_set_font (NAUTILUS_LABEL (client_data), font);
- color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
- NAUTILUS_RGBA_COLOR_GET_G (color),
- (guchar) adjustment->value,
- NAUTILUS_RGBA_COLOR_GET_A (color));
-
- nautilus_image_set_background_color (image, color);
+ g_free (family);
+ g_free (weight);
+ g_free (slant);
+ g_free (set_width);
- image_list = image_list->next;
- }
+ gtk_object_unref (GTK_OBJECT (font));
}
static void
-toggle_background_type_callback (GtkWidget *widget, gpointer client_data)
+text_caption_changed_callback (NautilusTextCaption *text_caption, gpointer client_data)
{
- NautilusImage *image;
+ NautilusLabel *label;
+ char *text;
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_BUTTON (widget));
- g_return_if_fail (client_data != NULL);
- g_return_if_fail (NAUTILUS_IS_IMAGE (client_data));
+ g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- image = NAUTILUS_IMAGE (client_data);
+ text = nautilus_text_caption_get_text (text_caption);
- if (nautilus_image_get_background_type (image) == NAUTILUS_IMAGE_BACKGROUND_PIXBUF)
- {
- nautilus_image_set_background_type (image, NAUTILUS_IMAGE_BACKGROUND_SOLID);
- }
- else
- {
- nautilus_image_set_background_type (image, NAUTILUS_IMAGE_BACKGROUND_PIXBUF);
- }
+ label = NAUTILUS_LABEL (client_data);
+
+ nautilus_label_set_text (NAUTILUS_LABEL (label), text);
+
+ g_free (text);
}
static GtkWidget*
-create_color_scale (guint num_colors, GtkSignalFunc callback, gpointer callback_data)
+create_value_scale (guint min,
+ guint max,
+ guint value,
+ const char *color_spec,
+ GtkSignalFunc callback,
+ gpointer callback_data)
{
GtkAdjustment *adjustment;
GtkWidget *scale;
- g_assert (num_colors > 0);
+ g_assert (max > min);
g_assert (callback > 0);
-
- adjustment = (GtkAdjustment *) gtk_adjustment_new (num_colors,
- 0,
- num_colors,
+
+ adjustment = (GtkAdjustment *) gtk_adjustment_new (value,
+ min,
+ max,
1,
- num_colors / 10,
+ (max - min) / 10,
0);
scale = gtk_hscale_new (adjustment);
- gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", callback, callback_data);
+ if (color_spec != NULL) {
+ nautilus_gtk_widget_set_background_color (scale, color_spec);
+ }
- gtk_widget_set_usize (scale, 150, 0);
+ gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+ gtk_widget_set_usize (scale, 150, 0);
+
+ gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", callback, callback_data);
+
return scale;
}
-int
-main (int argc, char* argv[])
+static GtkWidget*
+create_value_scale_caption (const gchar *title,
+ guint min,
+ guint max,
+ guint value,
+ const char *color_spec,
+ GtkSignalFunc callback,
+ gpointer callback_data)
{
- GtkWidget *window;
- GtkWidget *main_box;
- GtkWidget *image_box;
- GtkWidget *tool_box;
- GtkWidget *toggle_background_type;
+ GtkWidget *hbox;
+ GtkWidget *label;
+ GtkWidget *scale;
- GtkWidget *alpha_scale;
+ scale = create_value_scale (min, max, value, color_spec, callback, callback_data);
+ hbox = gtk_hbox_new (FALSE, 0);
+ label = gtk_label_new (title);
+
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
+ gtk_box_pack_end (GTK_BOX (hbox), scale, FALSE, FALSE, 4);
- GtkWidget *red_scale;
- GtkWidget *green_scale;
- GtkWidget *blue_scale;
+ gtk_widget_show (label);
+ gtk_widget_show (scale);
- GdkPixbuf *background;
+ return hbox;
+}
- GtkWidget *image1;
- GtkWidget *image2;
- GtkWidget *image3;
+static GtkWidget*
+create_color_picker_frame (const char *title,
+ GtkSignalFunc red_callback,
+ GtkSignalFunc green_callback,
+ GtkSignalFunc blue_callback,
+ GtkSignalFunc alpha_callback,
+ gpointer callback_data,
+ guint32 current_color)
+{
+ GtkWidget *red_scale;
+ GtkWidget *green_scale;
+ GtkWidget *blue_scale;
+ GtkWidget *alpha_scale;
+ GtkWidget *frame;
+ GtkWidget *vbox;
+
+ g_return_val_if_fail (title != NULL, NULL);
+ g_return_val_if_fail (red_callback != NULL, NULL);
+ g_return_val_if_fail (green_callback != NULL, NULL);
+ g_return_val_if_fail (blue_callback != NULL, NULL);
+ g_return_val_if_fail (alpha_callback != NULL, NULL);
+
+ frame = gtk_frame_new (title);
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
+
+ red_scale = create_value_scale_caption ("Red",
+ 0,
+ 255,
+ NAUTILUS_RGBA_COLOR_GET_R (current_color),
+ "red",
+ red_callback,
+ callback_data);
+
+ green_scale = create_value_scale_caption ("Green",
+ 0,
+ 255,
+ NAUTILUS_RGBA_COLOR_GET_R (current_color),
+ "green",
+ green_callback,
+ callback_data);
+
+ blue_scale = create_value_scale_caption ("Blue",
+ 0,
+ 255,
+ NAUTILUS_RGBA_COLOR_GET_R (current_color),
+ "blue",
+ blue_callback,
+ callback_data);
+
+ alpha_scale = create_value_scale_caption ("Alpha",
+ 0,
+ 255,
+ NAUTILUS_RGBA_COLOR_GET_R (current_color),
+ NULL,
+ alpha_callback,
+ callback_data);
- GtkWidget *background_image;
+ gtk_container_add (GTK_CONTAINER (frame), vbox);
- GList *image_list = NULL;
+ gtk_box_pack_start (GTK_BOX (vbox), red_scale, TRUE, TRUE, 2);
+ gtk_box_pack_start (GTK_BOX (vbox), green_scale, TRUE, TRUE, 1);
+ gtk_box_pack_start (GTK_BOX (vbox), blue_scale, TRUE, TRUE, 1);
+ gtk_box_pack_end (GTK_BOX (vbox), alpha_scale, TRUE, TRUE, 2);
- const char *file_name1 = "eazel-services-logo.png";
- const char *file_name2 = "eazel-services-logo-tile.png";
- const char *file_name3 = "eazel-services-logo-tile.png";
+ gtk_widget_show_all (vbox);
- gtk_init (&argc, &argv);
- gdk_rgb_init ();
+ return frame;
+}
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title (GTK_WINDOW (window), "Image Test");
- gtk_container_set_border_width (GTK_CONTAINER (window), 10);
+static GtkWidget*
+create_font_picker_frame (const char *title,
+ GtkSignalFunc changed_callback,
+ GtkSignalFunc size_changed_callback,
+ gpointer callback_data)
+{
+ GtkWidget *frame;
+ GtkWidget *hbox;
+ GtkWidget *font_picker;
+ GtkWidget *font_size_picker;
+ NautilusStringList *font_size_list;
+
+ g_return_val_if_fail (title != NULL, NULL);
+ g_return_val_if_fail (changed_callback != NULL, NULL);
+ g_return_val_if_fail (size_changed_callback != NULL, NULL);
+
+ frame = gtk_frame_new (title);
- main_box = gtk_vbox_new (FALSE, 0);
- gtk_container_add (GTK_CONTAINER (window), main_box);
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
+
+ gtk_container_add (GTK_CONTAINER (frame), hbox);
+
+ font_size_picker = nautilus_string_picker_new ();
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_size_picker), FALSE);
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_size_picker), _("Size"));
+
+ gtk_signal_connect (GTK_OBJECT (font_size_picker), "changed", size_changed_callback, callback_data);
+
+ font_size_list = nautilus_string_list_new_from_tokens ("5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,"
+ "30,40,50,60,70,80,90,100,110,120,130,140,"
+ "200,400,800", ",");
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_size_picker), font_size_list);
+ nautilus_string_list_free (font_size_list);
+
+ font_picker = nautilus_font_picker_new ();
+ gtk_signal_connect (GTK_OBJECT (font_picker), "selected_font_changed", changed_callback, callback_data);
+
+ gtk_box_pack_start (GTK_BOX (hbox), font_picker, TRUE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (hbox), font_size_picker, FALSE, FALSE, 5);
+
+ gtk_widget_show_all (hbox);
+
+ return frame;
+}
+
+static GtkWidget*
+create_text_caption_frame (const char *title,
+ GtkSignalFunc changed_callback,
+ gpointer callback_data)
+{
+ GtkWidget *frame;
+ GtkWidget *text_caption;
+
+ g_return_val_if_fail (title != NULL, NULL);
+ g_return_val_if_fail (changed_callback != NULL, NULL);
+
+ frame = gtk_frame_new (title);
+
+ text_caption = nautilus_text_caption_new ();
+ gtk_container_set_border_width (GTK_CONTAINER (text_caption), 6);
+
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (text_caption), FALSE);
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (text_caption), title);
+
+ gtk_signal_connect (GTK_OBJECT (text_caption), "changed", changed_callback, callback_data);
+
+ gtk_container_add (GTK_CONTAINER (frame), text_caption);
+
+ gtk_widget_show (text_caption);
+
+ return frame;
+}
+
+static void
+widget_set_background_image (GtkWidget *widget, const char *image_name)
+{
+ NautilusBackground *background;
+ char *background_uri;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (image_name != NULL);
+
+ background = nautilus_get_widget_background (widget);
+
+ background_uri = g_strdup_printf ("file://%s/backgrounds/%s", NAUTILUS_DATADIR, image_name);
+
+ nautilus_background_reset (background);
+ nautilus_background_set_image_uri (background, background_uri);
+
+ g_free (background_uri);
+}
+
+static void
+widget_set_background_color (GtkWidget *widget, const char *color)
+{
+ NautilusBackground *background;
- background = create_background ();
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (color != NULL);
- image1 = create_image (file_name1, background);
- image2 = create_image (file_name2, background);
- image3 = create_image (file_name3, background);
- background_image = create_image (NULL, background);
+ background = nautilus_get_widget_background (widget);
+
+ nautilus_background_reset (background);
+ nautilus_background_set_color (background, color);
+}
- image_list = g_list_append (image_list, image1);
- image_list = g_list_append (image_list, image2);
- image_list = g_list_append (image_list, image3);
- image_list = g_list_append (image_list, background_image);
+static void
+widget_set_background_reset (GtkWidget *widget)
+{
+ NautilusBackground *background;
- nautilus_image_set_placement_type (NAUTILUS_IMAGE (image2), NAUTILUS_IMAGE_PLACEMENT_TILE);
- nautilus_image_set_placement_type (NAUTILUS_IMAGE (image3), NAUTILUS_IMAGE_PLACEMENT_TILE);
+ g_return_if_fail (GTK_IS_WIDGET (widget));
- {
- GdkFont *font;
+ background = nautilus_get_widget_background (widget);
- font = nautilus_font_factory_get_font_by_family ("helvetica", 20);
+ nautilus_background_reset (background);
+}
- nautilus_image_set_label_text (NAUTILUS_IMAGE (image3), "Welcome Back, Arlo!");
- nautilus_image_set_label_font (NAUTILUS_IMAGE (image3), font);
+static void
+background_changed_callback (NautilusStringPicker *string_picker, gpointer client_data)
+{
+ char *string;
+
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
- gdk_font_unref (font);
+ string = nautilus_string_picker_get_selected_string (string_picker);
- nautilus_image_set_extra_width (NAUTILUS_IMAGE (image3), 8);
- nautilus_image_set_right_offset (NAUTILUS_IMAGE (image3), 8);
- nautilus_image_set_top_offset (NAUTILUS_IMAGE (image3), 3);
+ if (nautilus_str_has_prefix (string, "Image - ")) {
+ widget_set_background_image (nautilus_gtk_widget_find_windowed_ancestor (GTK_WIDGET (client_data)),
+ string + strlen ("Image - "));
+ }
+ else if (nautilus_str_has_prefix (string, "Gradient - ")) {
+ widget_set_background_color (nautilus_gtk_widget_find_windowed_ancestor (GTK_WIDGET (client_data)),
+ string + strlen ("Gradient - "));
+ }
+ else if (nautilus_str_has_prefix (string, "Solid - ")) {
+ widget_set_background_color (nautilus_gtk_widget_find_windowed_ancestor (GTK_WIDGET (client_data)),
+ string + strlen ("Solid - "));
+ }
+ else if (nautilus_str_has_prefix (string, "Reset")) {
+ widget_set_background_reset (nautilus_gtk_widget_find_windowed_ancestor (GTK_WIDGET (client_data)));
}
+
+ g_free (string);
+}
+
+static GtkWidget*
+create_background_frame (const char *title,
+ GtkSignalFunc background_changed_callback,
+ gpointer callback_data)
+{
+ GtkWidget *frame;
+ GtkWidget *vbox;
+ GtkWidget *background_picker;
+
+ g_return_val_if_fail (title != NULL, NULL);
+ g_return_val_if_fail (background_changed_callback != NULL, NULL);
- image_box = gtk_hbox_new (FALSE, 0);
- tool_box = gtk_hbox_new (FALSE, 0);
+ vbox = gtk_vbox_new (FALSE, 0);
+ frame = gtk_frame_new (title);
- gtk_box_pack_start (GTK_BOX (main_box), image_box, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (main_box), background_image, TRUE, TRUE, 0);
- gtk_box_pack_end (GTK_BOX (main_box), tool_box, FALSE, FALSE, 10);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
+ gtk_container_add (GTK_CONTAINER (frame), vbox);
- gtk_box_pack_start (GTK_BOX (image_box), image1, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (image_box), image2, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (image_box), image3, FALSE, FALSE, 0);
+ background_picker = nautilus_string_picker_new ();
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Image - pale_coins.png");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Image - bubbles.png");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Image - irish_spring.png");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Image - white_ribs.png");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "-----------------------");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Gradient - rgb:bbbb/bbbb/eeee-rgb:ffff/ffff/ffff:h");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Gradient - rgb:bbbb/bbbb/eeee-rgb:ffff/ffff/ffff");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "-----------------------");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Solid - rgb:bbbb/bbbb/eeee");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "-----------------------");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Reset");
- alpha_scale = create_color_scale (255, alpha_scale_value_changed, image_list);
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (background_picker), FALSE);
+
+ gtk_signal_connect (GTK_OBJECT (background_picker), "changed", background_changed_callback, callback_data);
+
+ gtk_box_pack_start (GTK_BOX (vbox), background_picker, FALSE, FALSE, 0);
+
+ gtk_widget_show_all (vbox);
+
+ return frame;
+}
- toggle_background_type = gtk_button_new_with_label ("Toggle Background Type");
- red_scale = create_color_scale (255, red_color_value_changed, image_list);
- green_scale = create_color_scale (255, green_color_value_changed, image_list);
- blue_scale = create_color_scale (255, blue_color_value_changed, image_list);
+int
+main (int argc, char* argv[])
+{
+ GtkWidget *window;
+ GtkWidget *main_box;
+ GtkWidget *bottom_box;
+ GtkWidget *tool_box1;
+ GtkWidget *tool_box2;
+ GtkWidget *tool_box3;
+ GtkWidget *color_tool_box;
+ GtkWidget *label;
+ GtkWidget *label_color_picker_frame;
+ GtkWidget *background_color_picker_frame;
+ GtkWidget *font_picker_frame;
+ GtkWidget *text_caption_frame;
+ GtkWidget *background_frame;
+
+ gtk_init (&argc, &argv);
+ gdk_rgb_init ();
+ gnome_vfs_init ();
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "Label Test");
+ gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 10);
+
+ main_box = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), main_box);
+
+ label = nautilus_label_new ();
+
+ bottom_box = gtk_vbox_new (FALSE, 4);
+
+ tool_box1 = gtk_hbox_new (FALSE, 0);
+ tool_box2 = gtk_hbox_new (FALSE, 0);
+ tool_box3 = gtk_hbox_new (FALSE, 0);
+
+ color_tool_box = gtk_hbox_new (FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (bottom_box), tool_box1, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (bottom_box), tool_box2, TRUE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (bottom_box), tool_box3, TRUE, TRUE, 10);
+
+ nautilus_label_set_text (NAUTILUS_LABEL (label), "Label that doesn't suck\nFoo\nBar");
+
+ gtk_box_pack_start (GTK_BOX (main_box), label, TRUE, TRUE, 10);
+ gtk_box_pack_end (GTK_BOX (main_box), bottom_box, TRUE, TRUE, 10);
+
+ widget_set_background_image (nautilus_gtk_widget_find_windowed_ancestor (label), "pale_coins.png");
- gtk_box_pack_start (GTK_BOX (tool_box), alpha_scale, FALSE, FALSE, 5);
- gtk_box_pack_start (GTK_BOX (tool_box), toggle_background_type, FALSE, FALSE, 5);
- gtk_box_pack_start (GTK_BOX (tool_box), red_scale, FALSE, FALSE, 5);
- gtk_box_pack_start (GTK_BOX (tool_box), green_scale, FALSE, FALSE, 5);
- gtk_box_pack_start (GTK_BOX (tool_box), blue_scale, FALSE, FALSE, 5);
-
- gtk_signal_connect (GTK_OBJECT (toggle_background_type),
- "clicked",
- GTK_SIGNAL_FUNC (toggle_background_type_callback),
- (gpointer) image1);
-
- gtk_signal_connect (GTK_OBJECT (toggle_background_type),
- "clicked",
- GTK_SIGNAL_FUNC (toggle_background_type_callback),
- (gpointer) image2);
- gtk_signal_connect (GTK_OBJECT (toggle_background_type),
- "clicked",
- GTK_SIGNAL_FUNC (toggle_background_type_callback),
- (gpointer) image3);
-
- gtk_signal_connect (GTK_OBJECT (toggle_background_type),
- "clicked",
- GTK_SIGNAL_FUNC (toggle_background_type_callback),
- (gpointer) background_image);
+ label_color_picker_frame = create_color_picker_frame ("Label Color",
+ red_label_color_value_changed_callback,
+ green_label_color_value_changed_callback,
+ blue_label_color_value_changed_callback,
+ alpha_label_color_value_changed_callback,
+ label,
+ nautilus_label_get_text_color (NAUTILUS_LABEL (label)));
+
+ background_color_picker_frame = create_color_picker_frame ("Background Color",
+ red_background_color_value_changed_callback,
+ green_background_color_value_changed_callback,
+ blue_background_color_value_changed_callback,
+ alpha_background_color_value_changed_callback,
+ label,
+ nautilus_label_get_text_color (NAUTILUS_LABEL (label)));
+
+ font_picker_frame = create_font_picker_frame ("Font",
+ font_changed_callback,
+ font_size_changed_callback,
+ label);
+
+ text_caption_frame = create_text_caption_frame ("Text",
+ text_caption_changed_callback,
+ label);
+
+ background_frame = create_background_frame ("Background",
+ background_changed_callback,
+ label);
+
+ gtk_box_pack_start (GTK_BOX (color_tool_box), label_color_picker_frame, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (color_tool_box), background_frame, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (color_tool_box), background_color_picker_frame, FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (tool_box1), color_tool_box, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (tool_box2), font_picker_frame, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (tool_box3), text_caption_frame, TRUE, TRUE, 0);
gtk_widget_show_all (window);
gtk_main ();
+
+ gnome_vfs_shutdown ();
return 0;
}
diff --git a/test/test-nautilus-label.c b/test/test-nautilus-label.c
new file mode 100644
index 000000000..b45cb7510
--- /dev/null
+++ b/test/test-nautilus-label.c
@@ -0,0 +1,677 @@
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <libnautilus-extensions/nautilus-background.h>
+#include <libnautilus-extensions/nautilus-file-utilities.h>
+#include <libnautilus-extensions/nautilus-font-factory.h>
+#include <libnautilus-extensions/nautilus-glib-extensions.h>
+#include <libnautilus-extensions/nautilus-gdk-extensions.h>
+#include <libnautilus-extensions/nautilus-gtk-extensions.h>
+#include <libnautilus-extensions/nautilus-icon-factory.h>
+#include <libnautilus-extensions/nautilus-string-list.h>
+#include <libnautilus-extensions/nautilus-string-picker.h>
+#include <libnautilus-extensions/nautilus-font-picker.h>
+#include <libnautilus-extensions/nautilus-text-caption.h>
+#include <libnautilus-extensions/nautilus-string.h>
+#include <libgnomevfs/gnome-vfs-init.h>
+
+#include <libnautilus-extensions/nautilus-scalable-font.h>
+#include <libnautilus-extensions/nautilus-label.h>
+#include <libnautilus-extensions/nautilus-image.h>
+
+static void
+red_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+ guint32 color;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
+
+ color = NAUTILUS_RGBA_COLOR_PACK ((guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_G (color),
+ NAUTILUS_RGBA_COLOR_GET_B (color),
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
+}
+
+static void
+green_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+ guint32 color;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
+
+ color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
+ (guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_B (color),
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
+}
+
+static void
+blue_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+ guint32 color;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
+
+ color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
+ NAUTILUS_RGBA_COLOR_GET_G (color),
+ (guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
+}
+
+static void
+alpha_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ label = NAUTILUS_LABEL (client_data);
+
+ nautilus_label_set_text_alpha (NAUTILUS_LABEL (label), (guchar) adjustment->value);
+}
+
+static void
+red_background_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+ guint32 color;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
+
+ color = NAUTILUS_RGBA_COLOR_PACK ((guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_G (color),
+ NAUTILUS_RGBA_COLOR_GET_B (color),
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
+}
+
+static void
+green_background_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+ guint32 color;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
+
+ color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
+ (guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_B (color),
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
+}
+
+static void
+blue_background_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+ guint32 color;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ label = NAUTILUS_LABEL (client_data);
+
+ color = nautilus_label_get_text_color (label);
+
+ color = NAUTILUS_RGBA_COLOR_PACK (NAUTILUS_RGBA_COLOR_GET_R (color),
+ NAUTILUS_RGBA_COLOR_GET_G (color),
+ (guchar) adjustment->value,
+ NAUTILUS_RGBA_COLOR_GET_A (color));
+
+ nautilus_label_set_text_color (label, color);
+}
+
+static void
+alpha_background_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
+{
+ NautilusLabel *label;
+
+ g_return_if_fail (adjustment != NULL);
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+ g_return_if_fail (client_data != NULL);
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ label = NAUTILUS_LABEL (client_data);
+
+ nautilus_label_set_text_alpha (NAUTILUS_LABEL (label), (guchar) adjustment->value);
+}
+
+static void
+font_size_changed_callback (NautilusStringPicker *string_picker, gpointer client_data)
+{
+ char *string;
+ int size;
+
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ string = nautilus_string_picker_get_selected_string (string_picker);
+
+ if (nautilus_eat_str_to_int (string, &size)) {
+ nautilus_label_set_font_size (NAUTILUS_LABEL (client_data), (guint) size);
+ }
+
+ g_free (string);
+}
+
+static void
+font_changed_callback (NautilusFontPicker *font_picker, gpointer client_data)
+{
+ NautilusScalableFont *font;
+ char *family;
+ char *weight;
+ char *slant;
+ char *set_width;
+
+ g_return_if_fail (NAUTILUS_IS_FONT_PICKER (font_picker));
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ family = nautilus_font_picker_get_selected_family (NAUTILUS_FONT_PICKER (font_picker));
+ weight = nautilus_font_picker_get_selected_weight (NAUTILUS_FONT_PICKER (font_picker));
+ slant = nautilus_font_picker_get_selected_slant (NAUTILUS_FONT_PICKER (font_picker));
+ set_width = nautilus_font_picker_get_selected_set_width (NAUTILUS_FONT_PICKER (font_picker));
+
+ g_print ("%s (%s,%s,%s,%s)\n", __FUNCTION__, family, weight, slant, set_width);
+
+ font = NAUTILUS_SCALABLE_FONT (nautilus_scalable_font_new (family, weight, slant, set_width));
+ g_assert (font != NULL);
+
+ nautilus_label_set_font (NAUTILUS_LABEL (client_data), font);
+
+ g_free (family);
+ g_free (weight);
+ g_free (slant);
+ g_free (set_width);
+
+ gtk_object_unref (GTK_OBJECT (font));
+}
+
+static void
+text_caption_changed_callback (NautilusTextCaption *text_caption, gpointer client_data)
+{
+ NautilusLabel *label;
+ char *text;
+
+ g_return_if_fail (NAUTILUS_IS_TEXT_CAPTION (text_caption));
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ text = nautilus_text_caption_get_text (text_caption);
+
+ label = NAUTILUS_LABEL (client_data);
+
+ nautilus_label_set_text (NAUTILUS_LABEL (label), text);
+
+ g_free (text);
+}
+
+static GtkWidget*
+create_value_scale (guint min,
+ guint max,
+ guint value,
+ const char *color_spec,
+ GtkSignalFunc callback,
+ gpointer callback_data)
+{
+ GtkAdjustment *adjustment;
+ GtkWidget *scale;
+
+ g_assert (max > min);
+ g_assert (callback > 0);
+
+ adjustment = (GtkAdjustment *) gtk_adjustment_new (value,
+ min,
+ max,
+ 1,
+ (max - min) / 10,
+ 0);
+
+ scale = gtk_hscale_new (adjustment);
+
+ if (color_spec != NULL) {
+ nautilus_gtk_widget_set_background_color (scale, color_spec);
+ }
+
+ gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+
+ gtk_widget_set_usize (scale, 150, 0);
+
+ gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed", callback, callback_data);
+
+ return scale;
+}
+
+static GtkWidget*
+create_value_scale_caption (const gchar *title,
+ guint min,
+ guint max,
+ guint value,
+ const char *color_spec,
+ GtkSignalFunc callback,
+ gpointer callback_data)
+{
+ GtkWidget *hbox;
+ GtkWidget *label;
+ GtkWidget *scale;
+
+ scale = create_value_scale (min, max, value, color_spec, callback, callback_data);
+ hbox = gtk_hbox_new (FALSE, 0);
+ label = gtk_label_new (title);
+
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
+ gtk_box_pack_end (GTK_BOX (hbox), scale, FALSE, FALSE, 4);
+
+ gtk_widget_show (label);
+ gtk_widget_show (scale);
+
+ return hbox;
+}
+
+static GtkWidget*
+create_color_picker_frame (const char *title,
+ GtkSignalFunc red_callback,
+ GtkSignalFunc green_callback,
+ GtkSignalFunc blue_callback,
+ GtkSignalFunc alpha_callback,
+ gpointer callback_data,
+ guint32 current_color)
+{
+ GtkWidget *red_scale;
+ GtkWidget *green_scale;
+ GtkWidget *blue_scale;
+ GtkWidget *alpha_scale;
+ GtkWidget *frame;
+ GtkWidget *vbox;
+
+ g_return_val_if_fail (title != NULL, NULL);
+ g_return_val_if_fail (red_callback != NULL, NULL);
+ g_return_val_if_fail (green_callback != NULL, NULL);
+ g_return_val_if_fail (blue_callback != NULL, NULL);
+ g_return_val_if_fail (alpha_callback != NULL, NULL);
+
+ frame = gtk_frame_new (title);
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
+
+ red_scale = create_value_scale_caption ("Red",
+ 0,
+ 255,
+ NAUTILUS_RGBA_COLOR_GET_R (current_color),
+ "red",
+ red_callback,
+ callback_data);
+
+ green_scale = create_value_scale_caption ("Green",
+ 0,
+ 255,
+ NAUTILUS_RGBA_COLOR_GET_R (current_color),
+ "green",
+ green_callback,
+ callback_data);
+
+ blue_scale = create_value_scale_caption ("Blue",
+ 0,
+ 255,
+ NAUTILUS_RGBA_COLOR_GET_R (current_color),
+ "blue",
+ blue_callback,
+ callback_data);
+
+ alpha_scale = create_value_scale_caption ("Alpha",
+ 0,
+ 255,
+ NAUTILUS_RGBA_COLOR_GET_R (current_color),
+ NULL,
+ alpha_callback,
+ callback_data);
+
+ gtk_container_add (GTK_CONTAINER (frame), vbox);
+
+ gtk_box_pack_start (GTK_BOX (vbox), red_scale, TRUE, TRUE, 2);
+ gtk_box_pack_start (GTK_BOX (vbox), green_scale, TRUE, TRUE, 1);
+ gtk_box_pack_start (GTK_BOX (vbox), blue_scale, TRUE, TRUE, 1);
+ gtk_box_pack_end (GTK_BOX (vbox), alpha_scale, TRUE, TRUE, 2);
+
+ gtk_widget_show_all (vbox);
+
+ return frame;
+}
+
+static GtkWidget*
+create_font_picker_frame (const char *title,
+ GtkSignalFunc changed_callback,
+ GtkSignalFunc size_changed_callback,
+ gpointer callback_data)
+{
+ GtkWidget *frame;
+ GtkWidget *hbox;
+ GtkWidget *font_picker;
+ GtkWidget *font_size_picker;
+ NautilusStringList *font_size_list;
+
+ g_return_val_if_fail (title != NULL, NULL);
+ g_return_val_if_fail (changed_callback != NULL, NULL);
+ g_return_val_if_fail (size_changed_callback != NULL, NULL);
+
+ frame = gtk_frame_new (title);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
+
+ gtk_container_add (GTK_CONTAINER (frame), hbox);
+
+ font_size_picker = nautilus_string_picker_new ();
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (font_size_picker), FALSE);
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (font_size_picker), _("Size"));
+
+ gtk_signal_connect (GTK_OBJECT (font_size_picker), "changed", size_changed_callback, callback_data);
+
+ font_size_list = nautilus_string_list_new_from_tokens ("5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,"
+ "30,40,50,60,70,80,90,100,110,120,130,140,"
+ "200,400,800", ",");
+
+ nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (font_size_picker), font_size_list);
+ nautilus_string_list_free (font_size_list);
+
+ font_picker = nautilus_font_picker_new ();
+ gtk_signal_connect (GTK_OBJECT (font_picker), "selected_font_changed", changed_callback, callback_data);
+
+ gtk_box_pack_start (GTK_BOX (hbox), font_picker, TRUE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (hbox), font_size_picker, FALSE, FALSE, 5);
+
+ gtk_widget_show_all (hbox);
+
+ return frame;
+}
+
+static GtkWidget*
+create_text_caption_frame (const char *title,
+ GtkSignalFunc changed_callback,
+ gpointer callback_data)
+{
+ GtkWidget *frame;
+ GtkWidget *text_caption;
+
+ g_return_val_if_fail (title != NULL, NULL);
+ g_return_val_if_fail (changed_callback != NULL, NULL);
+
+ frame = gtk_frame_new (title);
+
+ text_caption = nautilus_text_caption_new ();
+ gtk_container_set_border_width (GTK_CONTAINER (text_caption), 6);
+
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (text_caption), FALSE);
+ nautilus_caption_set_title_label (NAUTILUS_CAPTION (text_caption), title);
+
+ gtk_signal_connect (GTK_OBJECT (text_caption), "changed", changed_callback, callback_data);
+
+ gtk_container_add (GTK_CONTAINER (frame), text_caption);
+
+ gtk_widget_show (text_caption);
+
+ return frame;
+}
+
+static void
+widget_set_background_image (GtkWidget *widget, const char *image_name)
+{
+ NautilusBackground *background;
+ char *background_uri;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (image_name != NULL);
+
+ background = nautilus_get_widget_background (widget);
+
+ background_uri = g_strdup_printf ("file://%s/backgrounds/%s", NAUTILUS_DATADIR, image_name);
+
+ nautilus_background_reset (background);
+ nautilus_background_set_image_uri (background, background_uri);
+
+ g_free (background_uri);
+}
+
+static void
+widget_set_background_color (GtkWidget *widget, const char *color)
+{
+ NautilusBackground *background;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (color != NULL);
+
+ background = nautilus_get_widget_background (widget);
+
+ nautilus_background_reset (background);
+ nautilus_background_set_color (background, color);
+}
+
+static void
+widget_set_background_reset (GtkWidget *widget)
+{
+ NautilusBackground *background;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ background = nautilus_get_widget_background (widget);
+
+ nautilus_background_reset (background);
+}
+
+static void
+background_changed_callback (NautilusStringPicker *string_picker, gpointer client_data)
+{
+ char *string;
+
+ g_return_if_fail (NAUTILUS_IS_STRING_PICKER (string_picker));
+ g_return_if_fail (NAUTILUS_IS_LABEL (client_data));
+
+ string = nautilus_string_picker_get_selected_string (string_picker);
+
+ if (nautilus_str_has_prefix (string, "Image - ")) {
+ widget_set_background_image (nautilus_gtk_widget_find_windowed_ancestor (GTK_WIDGET (client_data)),
+ string + strlen ("Image - "));
+ }
+ else if (nautilus_str_has_prefix (string, "Gradient - ")) {
+ widget_set_background_color (nautilus_gtk_widget_find_windowed_ancestor (GTK_WIDGET (client_data)),
+ string + strlen ("Gradient - "));
+ }
+ else if (nautilus_str_has_prefix (string, "Solid - ")) {
+ widget_set_background_color (nautilus_gtk_widget_find_windowed_ancestor (GTK_WIDGET (client_data)),
+ string + strlen ("Solid - "));
+ }
+ else if (nautilus_str_has_prefix (string, "Reset")) {
+ widget_set_background_reset (nautilus_gtk_widget_find_windowed_ancestor (GTK_WIDGET (client_data)));
+ }
+
+ g_free (string);
+}
+
+static GtkWidget*
+create_background_frame (const char *title,
+ GtkSignalFunc background_changed_callback,
+ gpointer callback_data)
+{
+ GtkWidget *frame;
+ GtkWidget *vbox;
+ GtkWidget *background_picker;
+
+ g_return_val_if_fail (title != NULL, NULL);
+ g_return_val_if_fail (background_changed_callback != NULL, NULL);
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ frame = gtk_frame_new (title);
+
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
+ gtk_container_add (GTK_CONTAINER (frame), vbox);
+
+ background_picker = nautilus_string_picker_new ();
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Image - pale_coins.png");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Image - bubbles.png");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Image - irish_spring.png");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Image - white_ribs.png");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "-----------------------");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Gradient - rgb:bbbb/bbbb/eeee-rgb:ffff/ffff/ffff:h");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Gradient - rgb:bbbb/bbbb/eeee-rgb:ffff/ffff/ffff");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "-----------------------");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Solid - rgb:bbbb/bbbb/eeee");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "-----------------------");
+ nautilus_string_picker_insert_string (NAUTILUS_STRING_PICKER (background_picker), "Reset");
+
+ nautilus_caption_set_show_title (NAUTILUS_CAPTION (background_picker), FALSE);
+
+ gtk_signal_connect (GTK_OBJECT (background_picker), "changed", background_changed_callback, callback_data);
+
+ gtk_box_pack_start (GTK_BOX (vbox), background_picker, FALSE, FALSE, 0);
+
+ gtk_widget_show_all (vbox);
+
+ return frame;
+}
+
+int
+main (int argc, char* argv[])
+{
+ GtkWidget *window;
+ GtkWidget *main_box;
+ GtkWidget *bottom_box;
+ GtkWidget *tool_box1;
+ GtkWidget *tool_box2;
+ GtkWidget *tool_box3;
+ GtkWidget *color_tool_box;
+ GtkWidget *label;
+ GtkWidget *label_color_picker_frame;
+ GtkWidget *background_color_picker_frame;
+ GtkWidget *font_picker_frame;
+ GtkWidget *text_caption_frame;
+ GtkWidget *background_frame;
+
+ gtk_init (&argc, &argv);
+ gdk_rgb_init ();
+ gnome_vfs_init ();
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "Label Test");
+ gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (window), 10);
+
+ main_box = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), main_box);
+
+ label = nautilus_label_new ();
+
+ bottom_box = gtk_vbox_new (FALSE, 4);
+
+ tool_box1 = gtk_hbox_new (FALSE, 0);
+ tool_box2 = gtk_hbox_new (FALSE, 0);
+ tool_box3 = gtk_hbox_new (FALSE, 0);
+
+ color_tool_box = gtk_hbox_new (FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (bottom_box), tool_box1, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (bottom_box), tool_box2, TRUE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (bottom_box), tool_box3, TRUE, TRUE, 10);
+
+ nautilus_label_set_text (NAUTILUS_LABEL (label), "Label that doesn't suck\nFoo\nBar");
+
+ gtk_box_pack_start (GTK_BOX (main_box), label, TRUE, TRUE, 10);
+ gtk_box_pack_end (GTK_BOX (main_box), bottom_box, TRUE, TRUE, 10);
+
+ widget_set_background_image (nautilus_gtk_widget_find_windowed_ancestor (label), "pale_coins.png");
+
+ label_color_picker_frame = create_color_picker_frame ("Label Color",
+ red_label_color_value_changed_callback,
+ green_label_color_value_changed_callback,
+ blue_label_color_value_changed_callback,
+ alpha_label_color_value_changed_callback,
+ label,
+ nautilus_label_get_text_color (NAUTILUS_LABEL (label)));
+
+ background_color_picker_frame = create_color_picker_frame ("Background Color",
+ red_background_color_value_changed_callback,
+ green_background_color_value_changed_callback,
+ blue_background_color_value_changed_callback,
+ alpha_background_color_value_changed_callback,
+ label,
+ nautilus_label_get_text_color (NAUTILUS_LABEL (label)));
+
+ font_picker_frame = create_font_picker_frame ("Font",
+ font_changed_callback,
+ font_size_changed_callback,
+ label);
+
+ text_caption_frame = create_text_caption_frame ("Text",
+ text_caption_changed_callback,
+ label);
+
+ background_frame = create_background_frame ("Background",
+ background_changed_callback,
+ label);
+
+ gtk_box_pack_start (GTK_BOX (color_tool_box), label_color_picker_frame, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (color_tool_box), background_frame, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (color_tool_box), background_color_picker_frame, FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (tool_box1), color_tool_box, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (tool_box2), font_picker_frame, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (tool_box3), text_caption_frame, TRUE, TRUE, 0);
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+
+ gnome_vfs_shutdown ();
+
+ return 0;
+}