~ubuntu-branches/ubuntu/quantal/gnome-documents/quantal

« back to all changes in this revision

Viewing changes to src/lib/gd-tagged-entry.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-06-29 13:16:35 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120629131635-tkocc51xk4c37a39
Tags: 0.5.3-0ubuntu1
* New upstream release.
* debian/control.in:
  - Bump minimum GTK
  - Build-depend on libzapojit-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include <math.h>
25
25
 
26
 
G_DEFINE_TYPE (GdTaggedEntry, gd_tagged_entry, GTK_TYPE_ENTRY)
 
26
G_DEFINE_TYPE (GdTaggedEntry, gd_tagged_entry, GTK_TYPE_SEARCH_ENTRY)
27
27
 
28
28
#define BUTTON_INTERNAL_SPACING 6
29
29
 
45
45
  gboolean in_child_button;
46
46
  gboolean in_child_active;
47
47
  gboolean in_child_button_active;
 
48
  gboolean button_visible;
48
49
};
49
50
 
50
51
enum {
53
54
  LAST_SIGNAL
54
55
};
55
56
 
 
57
enum {
 
58
  PROP_0,
 
59
  PROP_TAG_BUTTON_VISIBLE,
 
60
  NUM_PROPERTIES
 
61
};
 
62
 
56
63
static guint signals[LAST_SIGNAL] = { 0, };
 
64
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
57
65
 
58
66
static void gd_tagged_entry_get_text_area_size (GtkEntry *entry,
59
67
                                                gint *x,
234
242
  GtkStyleContext *context;
235
243
  GtkStateFlags state;
236
244
  gint layout_width;
 
245
  gint button_width;
237
246
 
238
247
  gd_tagged_entry_tag_ensure_layout (tag, entry);
239
248
  pango_layout_get_pixel_size (tag->layout, &layout_width, NULL);
249
258
 
250
259
  g_object_unref (context);
251
260
 
 
261
  button_width = 0;
 
262
  if (entry->priv->button_visible)
 
263
    button_width = gdk_pixbuf_get_width (tag->close_pixbuf) + BUTTON_INTERNAL_SPACING;
 
264
 
252
265
  return layout_width + button_padding.left + button_padding.right +
253
266
    button_border.left + button_border.right +
254
267
    button_margin.left + button_margin.right +
255
 
    gdk_pixbuf_get_width (tag->close_pixbuf) + BUTTON_INTERNAL_SPACING;
 
268
    button_width;
256
269
}
257
270
 
258
271
static void
313
326
  layout_allocation.x += border.left + padding.left;
314
327
  layout_allocation.y += (layout_allocation.height - layout_height) / 2;
315
328
 
316
 
  pix_width = gdk_pixbuf_get_width (tag->close_pixbuf);
317
 
  pix_height = gdk_pixbuf_get_height (tag->close_pixbuf);
 
329
  if (entry->priv->button_visible)
 
330
    {
 
331
      pix_width = gdk_pixbuf_get_width (tag->close_pixbuf);
 
332
      pix_height = gdk_pixbuf_get_height (tag->close_pixbuf);
 
333
    }
 
334
  else
 
335
    {
 
336
      pix_width = 0;
 
337
      pix_height = 0;
 
338
    }
318
339
 
319
340
  button_allocation.x += width - pix_width - border.right - padding.right;
320
341
  button_allocation.y += (height - pix_height) / 2;
338
359
  GtkAllocation button_allocation;
339
360
  GtkStyleContext *context;
340
361
 
 
362
  if (!entry->priv->button_visible)
 
363
    return FALSE;
 
364
 
341
365
  context = gd_tagged_entry_tag_get_context (entry);
342
366
  gd_tagged_entry_tag_get_relative_allocations (tag, entry, context, NULL, NULL, &button_allocation);
343
367
 
388
412
 
389
413
  gtk_style_context_restore (context);
390
414
 
 
415
  if (!entry->priv->button_visible)
 
416
    goto done;
 
417
 
391
418
  gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
392
419
  state = gd_tagged_entry_tag_get_button_state (tag, entry);
393
420
  gtk_style_context_set_state (context, state);
414
441
                   tag->close_pixbuf,
415
442
                   button_allocation.x, button_allocation.y);
416
443
 
 
444
done:
417
445
  cairo_restore (cr);
418
446
 
419
447
  g_object_unref (context);
818
846
gd_tagged_entry_init (GdTaggedEntry *self)
819
847
{
820
848
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_TAGGED_ENTRY, GdTaggedEntryPrivate);
 
849
  self->priv->button_visible = TRUE;
 
850
}
 
851
 
 
852
static void
 
853
gd_tagged_entry_get_property (GObject      *object,
 
854
                              guint         property_id,
 
855
                              GValue       *value,
 
856
                              GParamSpec   *pspec)
 
857
{
 
858
  GdTaggedEntry *self = GD_TAGGED_ENTRY (object);
 
859
 
 
860
  switch (property_id)
 
861
    {
 
862
      case PROP_TAG_BUTTON_VISIBLE:
 
863
        g_value_set_boolean (value, gd_tagged_entry_get_tag_button_visible (self));
 
864
        break;
 
865
      default:
 
866
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
867
    }
 
868
}
 
869
 
 
870
static void
 
871
gd_tagged_entry_set_property (GObject      *object,
 
872
                              guint         property_id,
 
873
                              const GValue *value,
 
874
                              GParamSpec   *pspec)
 
875
{
 
876
  GdTaggedEntry *self = GD_TAGGED_ENTRY (object);
 
877
 
 
878
  switch (property_id)
 
879
    {
 
880
      case PROP_TAG_BUTTON_VISIBLE:
 
881
        gd_tagged_entry_set_tag_button_visible (self, g_value_get_boolean (value));
 
882
        break;
 
883
      default:
 
884
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
885
    }
821
886
}
822
887
 
823
888
static void
828
893
  GObjectClass *oclass = G_OBJECT_CLASS (klass);
829
894
 
830
895
  oclass->finalize = gd_tagged_entry_finalize;
 
896
  oclass->set_property = gd_tagged_entry_set_property;
 
897
  oclass->get_property = gd_tagged_entry_get_property;
831
898
 
832
899
  wclass->realize = gd_tagged_entry_realize;
833
900
  wclass->unrealize = gd_tagged_entry_unrealize;
859
926
                  G_TYPE_NONE,
860
927
                  1, G_TYPE_STRING);
861
928
 
 
929
  properties[PROP_TAG_BUTTON_VISIBLE] =
 
930
    g_param_spec_boolean ("tag-close-visible", "Tag close icon visibility",
 
931
                          "Whether the close button should be shown in tags.", TRUE,
 
932
                          G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
 
933
 
862
934
  g_type_class_add_private (klass, sizeof (GdTaggedEntryPrivate));
 
935
  g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
863
936
}
864
937
 
865
938
GdTaggedEntry *
939
1012
 
940
1013
  return res;  
941
1014
}
 
1015
 
 
1016
void
 
1017
gd_tagged_entry_set_tag_button_visible (GdTaggedEntry *self,
 
1018
                                        gboolean       visible)
 
1019
{
 
1020
  g_return_if_fail (GD_IS_TAGGED_ENTRY (self));
 
1021
 
 
1022
  if (self->priv->button_visible == visible)
 
1023
    return;
 
1024
 
 
1025
  self->priv->button_visible = visible;
 
1026
  gtk_widget_queue_resize (GTK_WIDGET (self));
 
1027
 
 
1028
  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TAG_BUTTON_VISIBLE]);
 
1029
}
 
1030
 
 
1031
gboolean
 
1032
gd_tagged_entry_get_tag_button_visible (GdTaggedEntry *self)
 
1033
{
 
1034
  g_return_val_if_fail (GD_IS_TAGGED_ENTRY (self), FALSE);
 
1035
 
 
1036
  return self->priv->button_visible;
 
1037
}