~optimisme/pantheon-files/1067061

« back to all changes in this revision

Viewing changes to src/nautilus-cell-renderer-text-ellipsized.c

  • Committer: am.monkeyd at gmail
  • Date: 2010-11-08 13:17:02 UTC
  • Revision ID: am.monkeyd@gmail.com-20101108131702-rqeywh4r5pyx2ycz
let's roll

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
 
2
 
 
3
   nautilus-cell-renderer-text-ellipsized.c: Cell renderer for text which
 
4
   will use pango ellipsization but deactivate it temporarily for the size
 
5
   calculation to get the size based on the actual text length.
 
6
 
 
7
   Copyright (C) 2007 Martin Wehner
 
8
  
 
9
   This program is free software; you can redistribute it and/or
 
10
   modify it under the terms of the GNU General Public License as
 
11
   published by the Free Software Foundation; either version 2 of the
 
12
   License, or (at your option) any later version.
 
13
  
 
14
   This program is distributed in the hope that it will be useful,
 
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
   General Public License for more details.
 
18
  
 
19
   You should have received a copy of the GNU General Public
 
20
   License along with this program; if not, write to the
 
21
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
22
   Boston, MA 02111-1307, USA.
 
23
  
 
24
   Author: Martin Wehner <martin.wehner@gmail.com>
 
25
*/
 
26
 
 
27
#include "nautilus-cell-renderer-text-ellipsized.h"
 
28
 
 
29
G_DEFINE_TYPE (NautilusCellRendererTextEllipsized, nautilus_cell_renderer_text_ellipsized,
 
30
               GTK_TYPE_CELL_RENDERER_TEXT);
 
31
 
 
32
static void
 
33
nautilus_cell_renderer_text_ellipsized_init (NautilusCellRendererTextEllipsized *cell)
 
34
{
 
35
        g_object_set (cell,
 
36
                      "ellipsize", PANGO_ELLIPSIZE_END,
 
37
                      "ellipsize-set", TRUE,
 
38
                      NULL);
 
39
}
 
40
 
 
41
static void
 
42
nautilus_cell_renderer_text_ellipsized_get_preferred_width (GtkCellRenderer *cell,
 
43
                                                            GtkWidget       *widget,
 
44
                                                            gint            *minimum_size,
 
45
                                                            gint            *natural_size)
 
46
{
 
47
        g_object_set (cell,
 
48
                      "ellipsize", PANGO_ELLIPSIZE_NONE,
 
49
                      "ellipsize-set", FALSE,
 
50
                      NULL);
 
51
 
 
52
        GTK_CELL_RENDERER_CLASS
 
53
                (nautilus_cell_renderer_text_ellipsized_parent_class)->get_preferred_width (cell, widget,
 
54
                                                                                            minimum_size, natural_size);
 
55
 
 
56
        g_object_set (cell,
 
57
                      "ellipsize", PANGO_ELLIPSIZE_END,
 
58
                      "ellipsize-set", TRUE,
 
59
                      NULL);
 
60
}
 
61
 
 
62
static void
 
63
nautilus_cell_renderer_text_ellipsized_class_init (NautilusCellRendererTextEllipsizedClass *klass)
 
64
{
 
65
        GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
 
66
 
 
67
        cell_class->get_preferred_width = nautilus_cell_renderer_text_ellipsized_get_preferred_width;
 
68
}
 
69
 
 
70
GtkCellRenderer *
 
71
nautilus_cell_renderer_text_ellipsized_new (void)
 
72
{
 
73
        return g_object_new (NAUTILUS_TYPE_CELL_RENDERER_TEXT_ELLIPSIZED, NULL);
 
74
}