~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/widgets/gimpcellrendererdashes.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimpcellrendererdashes.c
 
5
 * Copyright (C) 2005 Sven Neumann <sven@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include <config.h>
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include "widgets-types.h"
 
27
 
 
28
#include "core/gimpdashpattern.h"
 
29
 
 
30
#include "gimpcellrendererdashes.h"
 
31
 
 
32
 
 
33
#define DASHES_WIDTH   96
 
34
#define DASHES_HEIGHT   4
 
35
 
 
36
#define N_SEGMENTS     24
 
37
#define BLOCK_WIDTH    (DASHES_WIDTH / (2 * N_SEGMENTS))
 
38
 
 
39
 
 
40
enum
 
41
{
 
42
  PROP_0,
 
43
  PROP_PATTERN
 
44
};
 
45
 
 
46
 
 
47
static void gimp_cell_renderer_dashes_finalize     (GObject         *object);
 
48
static void gimp_cell_renderer_dashes_get_property (GObject         *object,
 
49
                                                    guint            param_id,
 
50
                                                    GValue          *value,
 
51
                                                    GParamSpec      *pspec);
 
52
static void gimp_cell_renderer_dashes_set_property (GObject         *object,
 
53
                                                    guint            param_id,
 
54
                                                    const GValue    *value,
 
55
                                                    GParamSpec      *pspec);
 
56
static void gimp_cell_renderer_dashes_get_size     (GtkCellRenderer *cell,
 
57
                                                    GtkWidget       *widget,
 
58
                                                    GdkRectangle    *rectangle,
 
59
                                                    gint            *x_offset,
 
60
                                                    gint            *y_offset,
 
61
                                                    gint            *width,
 
62
                                                    gint            *height);
 
63
static void gimp_cell_renderer_dashes_render       (GtkCellRenderer *cell,
 
64
                                                    GdkWindow       *window,
 
65
                                                    GtkWidget       *widget,
 
66
                                                    GdkRectangle    *background_area,
 
67
                                                    GdkRectangle    *cell_area,
 
68
                                                    GdkRectangle    *expose_area,
 
69
                                                    GtkCellRendererState flags);
 
70
 
 
71
 
 
72
G_DEFINE_TYPE (GimpCellRendererDashes, gimp_cell_renderer_dashes,
 
73
               GTK_TYPE_CELL_RENDERER)
 
74
 
 
75
#define parent_class gimp_cell_renderer_dashes_parent_class
 
76
 
 
77
 
 
78
static void
 
79
gimp_cell_renderer_dashes_class_init (GimpCellRendererDashesClass *klass)
 
80
{
 
81
  GObjectClass         *object_class = G_OBJECT_CLASS (klass);
 
82
  GtkCellRendererClass *cell_class   = GTK_CELL_RENDERER_CLASS (klass);
 
83
 
 
84
  object_class->finalize     = gimp_cell_renderer_dashes_finalize;
 
85
  object_class->get_property = gimp_cell_renderer_dashes_get_property;
 
86
  object_class->set_property = gimp_cell_renderer_dashes_set_property;
 
87
 
 
88
  cell_class->get_size       = gimp_cell_renderer_dashes_get_size;
 
89
  cell_class->render         = gimp_cell_renderer_dashes_render;
 
90
 
 
91
  g_object_class_install_property (object_class, PROP_PATTERN,
 
92
                                   g_param_spec_boxed ("pattern", NULL, NULL,
 
93
                                                       GIMP_TYPE_DASH_PATTERN,
 
94
                                                       GIMP_PARAM_WRITABLE));
 
95
}
 
96
 
 
97
static void
 
98
gimp_cell_renderer_dashes_init (GimpCellRendererDashes *dashes)
 
99
{
 
100
  dashes->segments = g_new0 (gboolean, N_SEGMENTS);
 
101
}
 
102
 
 
103
static void
 
104
gimp_cell_renderer_dashes_finalize (GObject *object)
 
105
{
 
106
  GimpCellRendererDashes *dashes = GIMP_CELL_RENDERER_DASHES (object);
 
107
 
 
108
  g_free (dashes->segments);
 
109
 
 
110
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
111
}
 
112
 
 
113
static void
 
114
gimp_cell_renderer_dashes_get_property (GObject    *object,
 
115
                                        guint       param_id,
 
116
                                        GValue     *value,
 
117
                                        GParamSpec *pspec)
 
118
{
 
119
  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 
120
}
 
121
 
 
122
static void
 
123
gimp_cell_renderer_dashes_set_property (GObject      *object,
 
124
                                        guint         param_id,
 
125
                                        const GValue *value,
 
126
                                        GParamSpec   *pspec)
 
127
{
 
128
  GimpCellRendererDashes *dashes = GIMP_CELL_RENDERER_DASHES (object);
 
129
 
 
130
  switch (param_id)
 
131
    {
 
132
    case PROP_PATTERN:
 
133
      gimp_dash_pattern_fill_segments (g_value_get_boxed (value),
 
134
                                       dashes->segments, N_SEGMENTS);
 
135
      break;
 
136
 
 
137
    default:
 
138
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 
139
      break;
 
140
    }
 
141
}
 
142
 
 
143
static void
 
144
gimp_cell_renderer_dashes_get_size (GtkCellRenderer *cell,
 
145
                                    GtkWidget       *widget,
 
146
                                    GdkRectangle    *cell_area,
 
147
                                    gint            *x_offset,
 
148
                                    gint            *y_offset,
 
149
                                    gint            *width,
 
150
                                    gint            *height)
 
151
{
 
152
  if (cell_area)
 
153
    {
 
154
      if (x_offset)
 
155
        {
 
156
          gdouble align;
 
157
 
 
158
          align = ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
 
159
                   1.0 - cell->xalign : cell->xalign);
 
160
 
 
161
          *x_offset = align * (cell_area->width - DASHES_WIDTH);
 
162
          *x_offset = MAX (*x_offset, 0) + cell->xpad;
 
163
        }
 
164
 
 
165
      if (y_offset)
 
166
        {
 
167
          *y_offset = cell->yalign * (cell_area->height - DASHES_HEIGHT);
 
168
          *y_offset = MAX (*y_offset, 0) + cell->ypad;
 
169
        }
 
170
    }
 
171
  else
 
172
    {
 
173
      if (x_offset)
 
174
        *x_offset = 0;
 
175
 
 
176
      if (y_offset)
 
177
        *y_offset = 0;
 
178
    }
 
179
 
 
180
  *width  = DASHES_WIDTH  + 2 * cell->xpad;
 
181
  *height = DASHES_HEIGHT + 2 * cell->ypad;
 
182
}
 
183
 
 
184
static void
 
185
gimp_cell_renderer_dashes_render (GtkCellRenderer      *cell,
 
186
                                  GdkWindow            *window,
 
187
                                  GtkWidget            *widget,
 
188
                                  GdkRectangle         *background_area,
 
189
                                  GdkRectangle         *cell_area,
 
190
                                  GdkRectangle         *expose_area,
 
191
                                  GtkCellRendererState  flags)
 
192
{
 
193
  GimpCellRendererDashes *dashes = GIMP_CELL_RENDERER_DASHES (cell);
 
194
  GtkStateType            state;
 
195
  gint                    width;
 
196
  gint                    x, y;
 
197
 
 
198
  if (! cell->sensitive)
 
199
    {
 
200
      state = GTK_STATE_INSENSITIVE;
 
201
    }
 
202
  else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
 
203
    {
 
204
      if (GTK_WIDGET_HAS_FOCUS (widget))
 
205
        state = GTK_STATE_SELECTED;
 
206
      else
 
207
        state = GTK_STATE_ACTIVE;
 
208
    }
 
209
  else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
 
210
           GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT)
 
211
    {
 
212
      state = GTK_STATE_PRELIGHT;
 
213
    }
 
214
  else
 
215
    {
 
216
      if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
 
217
        state = GTK_STATE_INSENSITIVE;
 
218
      else
 
219
        state = GTK_STATE_NORMAL;
 
220
    }
 
221
 
 
222
  y = cell_area->y + (cell_area->height - DASHES_HEIGHT) / 2;
 
223
  width = cell_area->width - 2 * cell->xpad;
 
224
 
 
225
  for (x = 0; x < width + BLOCK_WIDTH; x += BLOCK_WIDTH)
 
226
    {
 
227
      guint index = ((guint) x / BLOCK_WIDTH) % N_SEGMENTS;
 
228
 
 
229
      if (dashes->segments[index])
 
230
        {
 
231
          GdkRectangle  rect;
 
232
 
 
233
          rect.x      = cell_area->x + cell->xpad + x;
 
234
          rect.y      = y;
 
235
          rect.width  = MIN (BLOCK_WIDTH, width - x);
 
236
          rect.height = DASHES_HEIGHT;
 
237
 
 
238
          gdk_rectangle_intersect (&rect, expose_area, &rect);
 
239
          gdk_draw_rectangle (widget->window,
 
240
                              widget->style->text_gc[state], TRUE,
 
241
                              rect.x, rect.y, rect.width, rect.height);
 
242
        }
 
243
    }
 
244
}
 
245
 
 
246
GtkCellRenderer *
 
247
gimp_cell_renderer_dashes_new (void)
 
248
{
 
249
  return g_object_new (GIMP_TYPE_CELL_RENDERER_DASHES, NULL);
 
250
}