diff options
author | Martin Wehner <martin.wehner@gmail.com> | 2007-08-02 00:07:40 +0000 |
---|---|---|
committer | Martin Wehner <mwehner@src.gnome.org> | 2007-08-02 00:07:40 +0000 |
commit | 4f0eb50c350476f84acd40c776b7db892a093553 (patch) | |
tree | 171f5f7f3308c46d0a5658dbc128da41d2766aa2 /libnautilus-private | |
parent | 1ff2c6e19b6359c1b697906c4e0950ccba1942b4 (diff) | |
download | nautilus-4f0eb50c350476f84acd40c776b7db892a093553.tar.gz |
Use a custom cell renderer for the filename column which applies
2007-08-01 Martin Wehner <martin.wehner@gmail.com>
* libnautilus-private/Makefile.am:
* libnautilus-private/nautilus-cell-renderer-text-ellipsized.c:
* libnautilus-private/nautilus-cell-renderer-text-ellipsized.h:
* src/file-manager/fm-list-view.c: (create_and_set_up_tree_view):
Use a custom cell renderer for the filename column which applies
ellipsization but reports its size based on the actual width of
the text to be rendered. This restores the original column
autosizing behaviour while keeping the ellipsization. (#419343)
svn path=/trunk/; revision=13045
Diffstat (limited to 'libnautilus-private')
-rw-r--r-- | libnautilus-private/Makefile.am | 2 | ||||
-rw-r--r-- | libnautilus-private/nautilus-cell-renderer-text-ellipsized.c | 110 | ||||
-rw-r--r-- | libnautilus-private/nautilus-cell-renderer-text-ellipsized.h | 58 |
3 files changed, 170 insertions, 0 deletions
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am index fdfed66c8..260742cfd 100644 --- a/libnautilus-private/Makefile.am +++ b/libnautilus-private/Makefile.am @@ -55,6 +55,8 @@ libnautilus_private_la_SOURCES = \ nautilus-bookmark.h \ nautilus-cell-renderer-pixbuf-emblem.c \ nautilus-cell-renderer-pixbuf-emblem.h \ + nautilus-cell-renderer-text-ellipsized.c \ + nautilus-cell-renderer-text-ellipsized.h \ nautilus-clipboard-monitor.c \ nautilus-clipboard-monitor.h \ nautilus-clipboard.c \ diff --git a/libnautilus-private/nautilus-cell-renderer-text-ellipsized.c b/libnautilus-private/nautilus-cell-renderer-text-ellipsized.c new file mode 100644 index 000000000..e9f85d778 --- /dev/null +++ b/libnautilus-private/nautilus-cell-renderer-text-ellipsized.c @@ -0,0 +1,110 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- + + nautilus-cell-renderer-text-ellipsized.c: Cell renderer for text which + will use pango ellipsization but deactivate it temporarily for the size + calculation to get the size based on the actual text length. + + Copyright (C) 2007 Martin Wehner + + 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: Martin Wehner <martin.wehner@gmail.com> +*/ + +#include "nautilus-cell-renderer-text-ellipsized.h" + +#define ELLIPSIZE_PROP "ellipsize" + +static void nautilus_cell_renderer_text_ellipsized_init (NautilusCellRendererTextEllipsizedClass *cell); +static void nautilus_cell_renderer_text_ellipsized_class_init (NautilusCellRendererTextEllipsizedClass *klass); +static void nautilus_cell_renderer_text_ellipsized_get_size (GtkCellRenderer *cell, + GtkWidget *widget, + GdkRectangle *rectangle, + gint *x_offset, + gint *y_offset, + gint *width, + gint *height); + +static gpointer parent_class; + +GType +nautilus_cell_renderer_text_ellipsized_get_type (void) +{ + static GType type = 0; + + if (!type) { + const GTypeInfo info = + { + sizeof (NautilusCellRendererTextEllipsizedClass), + NULL, + NULL, + (GClassInitFunc) nautilus_cell_renderer_text_ellipsized_class_init, + NULL, + NULL, + sizeof (NautilusCellRendererTextEllipsized), + 0, + (GInstanceInitFunc) nautilus_cell_renderer_text_ellipsized_init + }; + + type = g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT, + "NautilusCellRendererTextEllipsized", + &info, 0); + } + + return type; +} + + +static void +nautilus_cell_renderer_text_ellipsized_init (NautilusCellRendererTextEllipsizedClass *cell) +{ + g_object_set (cell, ELLIPSIZE_PROP, PANGO_ELLIPSIZE_END, NULL); +} + +static void +nautilus_cell_renderer_text_ellipsized_class_init (NautilusCellRendererTextEllipsizedClass *klass) +{ + GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + cell_class->get_size = nautilus_cell_renderer_text_ellipsized_get_size; +} + +GtkCellRenderer * +nautilus_cell_renderer_text_ellipsized_new (void) +{ + return g_object_new (NAUTILUS_TYPE_CELL_RENDERER_TEXT_ELLIPSIZED, NULL); +} + +static void +nautilus_cell_renderer_text_ellipsized_get_size (GtkCellRenderer *cell, + GtkWidget *widget, + GdkRectangle *cell_area, + gint *x_offset, + gint *y_offset, + gint *width, + gint *height) +{ + g_object_set (cell, ELLIPSIZE_PROP, PANGO_ELLIPSIZE_NONE, NULL); + + (* GTK_CELL_RENDERER_CLASS (parent_class)->get_size) (cell, widget, cell_area, + x_offset, y_offset, + width, height); + + g_object_set (cell, ELLIPSIZE_PROP, PANGO_ELLIPSIZE_END, NULL); +} + diff --git a/libnautilus-private/nautilus-cell-renderer-text-ellipsized.h b/libnautilus-private/nautilus-cell-renderer-text-ellipsized.h new file mode 100644 index 000000000..7c4004f92 --- /dev/null +++ b/libnautilus-private/nautilus-cell-renderer-text-ellipsized.h @@ -0,0 +1,58 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- + + nautilus-cell-renderer-text-ellipsized.c: Cell renderer for text which + will use pango ellipsization but deactivate it temporarily for the size + calculation to get the size based on the actual text length. + + Copyright (C) 2007 Martin Wehner + + 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: Martin Wehner <martin.wehner@gmail.com> +*/ + +#ifndef NAUTILUS_CELL_RENDERER_TEXT_ELLIPSIZED_H +#define NAUTILUS_CELL_RENDERER_TEXT_ELLIPSIZED_H + +#include <gtk/gtkcellrenderer.h> +#include <gtk/gtkcellrenderertext.h> + +#define NAUTILUS_TYPE_CELL_RENDERER_TEXT_ELLIPSIZED \ + (nautilus_cell_renderer_text_ellipsized_get_type ()) +#define NAUTILUS_CELL_RENDERER_TEXT_ELLIPSIZED(obj) \ + (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_CELL_RENDERER_TEXT_ELLIPSIZED, NautilusCellRendererTextEllipsized)) +#define NAUTILUS_CELL_RENDERER_TEXT_ELLIPSIZED_CLASS(klass) \ + (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_CELL_RENDERER_TEXT_ELLIPSIZED, NautilusCellRendererTextEllipsizedClass)) +#define NAUTILUS_IS_CELL_RENDERER_TEXT_ELLIPSIZED(obj) \ + (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_CELL_RENDERER_TEXT_ELLIPSIZED)) +#define NAUTILUS_IS_CELL_RENDERER_TEXT_ELLIPSIZED_CLASS(klass) \ + (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_CELL_RENDERER_TEXT_ELLIPSIZED)) + +typedef struct _NautilusCellRendererTextEllipsized NautilusCellRendererTextEllipsized; +typedef struct _NautilusCellRendererTextEllipsizedClass NautilusCellRendererTextEllipsizedClass; + +struct _NautilusCellRendererTextEllipsized { + GtkCellRendererText parent; +}; + +struct _NautilusCellRendererTextEllipsizedClass { + GtkCellRendererTextClass parent_class; +}; + +GType nautilus_cell_renderer_text_ellipsized_get_type (void); +GtkCellRenderer *nautilus_cell_renderer_text_ellipsized_new (void); + +#endif /* NAUTILUS_CELL_RENDERER_TEXT_ELLIPSIZED_H */ |