mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-08-25 02:36:07 +00:00
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.
This commit is contained in:
parent
0198de152d
commit
7050528710
73
ChangeLog
73
ChangeLog
|
@ -1,3 +1,76 @@
|
|||
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:
|
||||
|
|
|
@ -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);
|
||||
/* nautilus_image_set_background_type (NAUTILUS_IMAGE (image),*/
|
||||
/* NAUTILUS_IMAGE_BACKGROUND_SOLID);*/
|
||||
|
||||
background_rgb = nautilus_parse_rgb_with_white_default (background_color_spec);
|
||||
/* background_rgb = nautilus_parse_rgb_with_white_default (background_color_spec);*/
|
||||
|
||||
nautilus_image_set_background_color (NAUTILUS_IMAGE (image),
|
||||
background_rgb);
|
||||
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
668
libnautilus-extensions/nautilus-buffered-widget.c
Normal file
668
libnautilus-extensions/nautilus-buffered-widget.c
Normal file
|
@ -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;
|
||||
}
|
87
libnautilus-extensions/nautilus-buffered-widget.h
Normal file
87
libnautilus-extensions/nautilus-buffered-widget.h
Normal file
|
@ -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 */
|
||||
|
||||
|
497
libnautilus-extensions/nautilus-font-picker.c
Normal file
497
libnautilus-extensions/nautilus-font-picker.c
Normal file
|
@ -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));
|
||||
}
|
80
libnautilus-extensions/nautilus-font-picker.h
Normal file
80
libnautilus-extensions/nautilus-font-picker.h
Normal file
|
@ -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 */
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||
|
||||
|
|
569
libnautilus-extensions/nautilus-label.c
Normal file
569
libnautilus-extensions/nautilus-label.c
Normal file
|
@ -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;
|
||||
}
|
102
libnautilus-extensions/nautilus-label.h
Normal file
102
libnautilus-extensions/nautilus-label.h
Normal file
|
@ -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 */
|
||||
|
||||
|
|
@ -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) \
|
||||
|
|
1056
libnautilus-extensions/nautilus-scalable-font.c
Normal file
1056
libnautilus-extensions/nautilus-scalable-font.c
Normal file
File diff suppressed because it is too large
Load diff
138
libnautilus-extensions/nautilus-scalable-font.h
Normal file
138
libnautilus-extensions/nautilus-scalable-font.h
Normal file
|
@ -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 */
|
||||
|
||||
|
295
libnautilus-extensions/nautilus-string-map.c
Normal file
295
libnautilus-extensions/nautilus-string-map.c
Normal file
|
@ -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 */
|
46
libnautilus-extensions/nautilus-string-map.h
Normal file
46
libnautilus-extensions/nautilus-string-map.h
Normal file
|
@ -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 */
|
||||
|
|
@ -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)
|
||||
|
|
668
libnautilus-private/nautilus-buffered-widget.c
Normal file
668
libnautilus-private/nautilus-buffered-widget.c
Normal file
|
@ -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;
|
||||
}
|
87
libnautilus-private/nautilus-buffered-widget.h
Normal file
87
libnautilus-private/nautilus-buffered-widget.h
Normal file
|
@ -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 */
|
||||
|
||||
|
497
libnautilus-private/nautilus-font-picker.c
Normal file
497
libnautilus-private/nautilus-font-picker.c
Normal file
|
@ -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));
|
||||
}
|
80
libnautilus-private/nautilus-font-picker.h
Normal file
80
libnautilus-private/nautilus-font-picker.h
Normal file
|
@ -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 */
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||
|
||||
|
|
569
libnautilus-private/nautilus-label.c
Normal file
569
libnautilus-private/nautilus-label.c
Normal file
|
@ -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;
|
||||
}
|
102
libnautilus-private/nautilus-label.h
Normal file
102
libnautilus-private/nautilus-label.h
Normal file
|
@ -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 */
|
||||
|
||||
|
|
@ -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) \
|
||||
|
|
1056
libnautilus-private/nautilus-scalable-font.c
Normal file
1056
libnautilus-private/nautilus-scalable-font.c
Normal file
File diff suppressed because it is too large
Load diff
138
libnautilus-private/nautilus-scalable-font.h
Normal file
138
libnautilus-private/nautilus-scalable-font.h
Normal file
|
@ -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 */
|
||||
|
||||
|
295
libnautilus-private/nautilus-string-map.c
Normal file
295
libnautilus-private/nautilus-string-map.c
Normal file
|
@ -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 */
|
46
libnautilus-private/nautilus-string-map.h
Normal file
46
libnautilus-private/nautilus-string-map.h
Normal file
|
@ -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 */
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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_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_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_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
|
||||
|
|
55
test/test-nautilus-font-picker.c
Normal file
55
test/test-nautilus-font-picker.c
Normal file
|
@ -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;
|
||||
}
|
77
test/test-nautilus-font.c
Normal file
77
test/test-nautilus-font.c
Normal file
|
@ -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;
|
||||
}
|
|
@ -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>
|
||||
|
||||
static GdkPixbuf*
|
||||
create_background (void)
|
||||
#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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static GdkPixbuf*
|
||||
create_pixbuf (const char *name)
|
||||
{
|
||||
char *icon_path;
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
|
||||
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 ((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);
|
||||
}
|
||||
|
||||
g_assert (pixbuf != NULL);
|
||||
static void
|
||||
green_label_color_value_changed_callback (GtkAdjustment *adjustment, gpointer client_data)
|
||||
{
|
||||
NautilusLabel *label;
|
||||
guint32 color;
|
||||
|
||||
g_free (icon_path);
|
||||
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 pixbuf;
|
||||
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_image (const char *name, GdkPixbuf *background)
|
||||
{
|
||||
GtkWidget *image;
|
||||
GdkPixbuf *pixbuf;
|
||||
|
||||
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);
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
pixbuf = create_pixbuf (name);
|
||||
g_assert (pixbuf != NULL);
|
||||
|
||||
nautilus_image_set_pixbuf (NAUTILUS_IMAGE (image), pixbuf);
|
||||
|
||||
gdk_pixbuf_unref (pixbuf);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
static void
|
||||
alpha_scale_value_changed (GtkAdjustment *adjustment, 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);
|
||||
|
||||
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);
|
||||
|
||||
image_list = image_list->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
red_color_value_changed (GtkAdjustment *adjustment, 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);
|
||||
|
||||
image_list = (GList *) client_data;
|
||||
|
||||
while (image_list)
|
||||
{
|
||||
NautilusImage *image;
|
||||
guint32 color;
|
||||
|
||||
g_assert (image_list->data != NULL);
|
||||
g_assert (NAUTILUS_IS_IMAGE (image_list->data));
|
||||
|
||||
image = NAUTILUS_IMAGE (image_list->data);
|
||||
|
||||
color = nautilus_image_get_background_color (image);
|
||||
|
||||
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);
|
||||
|
||||
image_list = image_list->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
green_color_value_changed (GtkAdjustment *adjustment, 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);
|
||||
|
||||
image_list = (GList *) client_data;
|
||||
|
||||
while (image_list)
|
||||
{
|
||||
NautilusImage *image;
|
||||
guint32 color;
|
||||
|
||||
g_assert (image_list->data != NULL);
|
||||
g_assert (NAUTILUS_IS_IMAGE (image_list->data));
|
||||
|
||||
image = NAUTILUS_IMAGE (image_list->data);
|
||||
|
||||
color = nautilus_image_get_background_color (image);
|
||||
|
||||
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);
|
||||
|
||||
image_list = image_list->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
blue_color_value_changed (GtkAdjustment *adjustment, 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);
|
||||
|
||||
image_list = (GList *) client_data;
|
||||
|
||||
while (image_list)
|
||||
{
|
||||
NautilusImage *image;
|
||||
guint32 color;
|
||||
|
||||
g_assert (image_list->data != NULL);
|
||||
g_assert (NAUTILUS_IS_IMAGE (image_list->data));
|
||||
|
||||
image = NAUTILUS_IMAGE (image_list->data);
|
||||
|
||||
color = nautilus_image_get_background_color (image);
|
||||
|
||||
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);
|
||||
|
||||
image_list = image_list->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
toggle_background_type_callback (GtkWidget *widget, gpointer client_data)
|
||||
{
|
||||
NautilusImage *image;
|
||||
|
||||
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));
|
||||
|
||||
image = NAUTILUS_IMAGE (client_data);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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_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 *image_box;
|
||||
GtkWidget *tool_box;
|
||||
GtkWidget *toggle_background_type;
|
||||
|
||||
GtkWidget *alpha_scale;
|
||||
|
||||
GtkWidget *red_scale;
|
||||
GtkWidget *green_scale;
|
||||
GtkWidget *blue_scale;
|
||||
|
||||
GdkPixbuf *background;
|
||||
|
||||
GtkWidget *image1;
|
||||
GtkWidget *image2;
|
||||
GtkWidget *image3;
|
||||
|
||||
GtkWidget *background_image;
|
||||
|
||||
GList *image_list = NULL;
|
||||
|
||||
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";
|
||||
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), "Image Test");
|
||||
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);
|
||||
|
||||
background = create_background ();
|
||||
label = nautilus_label_new ();
|
||||
|
||||
image1 = create_image (file_name1, background);
|
||||
image2 = create_image (file_name2, background);
|
||||
image3 = create_image (file_name3, background);
|
||||
background_image = create_image (NULL, background);
|
||||
bottom_box = gtk_vbox_new (FALSE, 4);
|
||||
|
||||
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);
|
||||
tool_box1 = gtk_hbox_new (FALSE, 0);
|
||||
tool_box2 = gtk_hbox_new (FALSE, 0);
|
||||
tool_box3 = gtk_hbox_new (FALSE, 0);
|
||||
|
||||
nautilus_image_set_placement_type (NAUTILUS_IMAGE (image2), NAUTILUS_IMAGE_PLACEMENT_TILE);
|
||||
nautilus_image_set_placement_type (NAUTILUS_IMAGE (image3), NAUTILUS_IMAGE_PLACEMENT_TILE);
|
||||
color_tool_box = gtk_hbox_new (FALSE, 0);
|
||||
|
||||
{
|
||||
GdkFont *font;
|
||||
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);
|
||||
|
||||
font = nautilus_font_factory_get_font_by_family ("helvetica", 20);
|
||||
nautilus_label_set_text (NAUTILUS_LABEL (label), "Label that doesn't suck\nFoo\nBar");
|
||||
|
||||
nautilus_image_set_label_text (NAUTILUS_IMAGE (image3), "Welcome Back, Arlo!");
|
||||
nautilus_image_set_label_font (NAUTILUS_IMAGE (image3), font);
|
||||
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);
|
||||
|
||||
gdk_font_unref (font);
|
||||
|
||||
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);
|
||||
}
|
||||
widget_set_background_image (nautilus_gtk_widget_find_windowed_ancestor (label), "pale_coins.png");
|
||||
|
||||
image_box = gtk_hbox_new (FALSE, 0);
|
||||
tool_box = gtk_hbox_new (FALSE, 0);
|
||||
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)));
|
||||
|
||||
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);
|
||||
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)));
|
||||
|
||||
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);
|
||||
font_picker_frame = create_font_picker_frame ("Font",
|
||||
font_changed_callback,
|
||||
font_size_changed_callback,
|
||||
label);
|
||||
|
||||
alpha_scale = create_color_scale (255, alpha_scale_value_changed, image_list);
|
||||
text_caption_frame = create_text_caption_frame ("Text",
|
||||
text_caption_changed_callback,
|
||||
label);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
background_frame = create_background_frame ("Background",
|
||||
background_changed_callback,
|
||||
label);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (toggle_background_type),
|
||||
"clicked",
|
||||
GTK_SIGNAL_FUNC (toggle_background_type_callback),
|
||||
(gpointer) image1);
|
||||
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_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);
|
||||
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;
|
||||
}
|
||||
|
|
677
test/test-nautilus-label.c
Normal file
677
test/test-nautilus-label.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue