aboutsummaryrefslogtreecommitdiff
path: root/hildon/hildon-bread-crumb-trail.c
blob: 6639136472a093c8232ef6f74115f3b48df83f90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/*
 * This file is a part of hildon
 *
 * Copyright (C) 2007 Nokia Corporation, all rights reserved.
 *
 * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
 * Author: Xan Lopez <xan.lopez@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */


/**
 * SECTION:hildon-bread-crumb-trail
 * @short_description: Widget used to represent a specific path in a hierarchical tree.
 * Stability: Unstable
 *
 * HildonBreadCrumbTrail is a GTK widget used to represent the currently active path in
 * some kind of hierarchical structure (file system, media library, structured document, etc).
 *
 * It has built-in support for text and icon bread crumbs, but the trail only requires a very
 * simple interface to be implemented for its children and thus new types of items can be
 * implemented if needed. See #HildonBreadCrumb for more details.
 *
 * #HildonBreadCrumbTrail is deprecated since hildon 2.2. You should instead use
 * #HildonStackableWindow to represent hierarchical structure in
 * applications.
 */

#undef HILDON_DISABLE_DEPRECATED

#include <gdk/gdkkeysyms.h>

#include "hildon-marshalers.h"
#include "hildon-bread-crumb-trail.h"
#include "hildon-bread-crumb-widget.h"

#define HILDON_BREAD_CRUMB_TRAIL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_BREAD_CRUMB_TRAIL, HildonBreadCrumbTrailPrivate))

struct _HildonBreadCrumbTrailPrivate
{
  GtkWidget *back_button;
  GList *item_list;
  GtkWidget *arrow;
};

/* Signals */

enum {
  CRUMB_CLICKED,
  MOVE_PARENT,
  LAST_SIGNAL
};

/* Properties */

enum {
  PROP_0
};

static void hildon_bread_crumb_trail_size_request (GtkWidget *widget,
                                                   GtkRequisition *requisition);
static void hildon_bread_crumb_trail_size_allocate (GtkWidget *widget,
                                                    GtkAllocation *allocation);
static void hildon_bread_crumb_trail_add (GtkContainer *container,
                                          GtkWidget *widget);
static void hildon_bread_crumb_trail_forall (GtkContainer *container,
                                             gboolean include_internals,
                                             GtkCallback callback,
                                             gpointer callback_data);
static void hildon_bread_crumb_trail_remove (GtkContainer *container,
                                             GtkWidget *widget);
static void hildon_bread_crumb_trail_finalize (GObject *object);
static void hildon_bread_crumb_trail_scroll_back (GtkWidget *button,
                                                  HildonBreadCrumbTrail *bct);
static void hildon_bread_crumb_trail_update_back_button_sensitivity (HildonBreadCrumbTrail *bct);
static void hildon_bread_crumb_trail_move_parent (HildonBreadCrumbTrail *bct);

static gpointer get_bread_crumb_id (HildonBreadCrumb *item);

static guint bread_crumb_trail_signals[LAST_SIGNAL] = { 0 };

/* GType methods */

G_DEFINE_TYPE (HildonBreadCrumbTrail, hildon_bread_crumb_trail, GTK_TYPE_CONTAINER)

static void
hildon_bread_crumb_trail_class_init (HildonBreadCrumbTrailClass *klass)
{
  GObjectClass *gobject_class = (GObjectClass*)klass;
  GtkObjectClass *object_class = (GtkObjectClass*)klass;
  GtkWidgetClass *widget_class = (GtkWidgetClass*)klass;
  GtkContainerClass *container_class = (GtkContainerClass*)klass;
  GtkBindingSet *binding_set;

  /* GObject signals */
  gobject_class->finalize = hildon_bread_crumb_trail_finalize;

  /* GtkWidget signals */
  widget_class->size_request = hildon_bread_crumb_trail_size_request;
  widget_class->size_allocate = hildon_bread_crumb_trail_size_allocate;

  /* GtkContainer signals */
  container_class->add = hildon_bread_crumb_trail_add;
  container_class->forall = hildon_bread_crumb_trail_forall;
  container_class->remove = hildon_bread_crumb_trail_remove;

  /* HildonBreadCrumbTrail signals */
  klass->move_parent = hildon_bread_crumb_trail_move_parent;

  /* Style properties */

#define _BREAD_CRUMB_TRAIL_MINIMUM_WIDTH 10

  /* FIXME: is this the best way to do it? */
  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_int ("minimum-width",
                                                             "Minimum width",
                                                             "The minimum width in characters the children widgets will request",
                                                             0,
                                                             G_MAXINT,
                                                             _BREAD_CRUMB_TRAIL_MINIMUM_WIDTH,
                                                             G_PARAM_READABLE));

#define _BREAD_CRUMB_TRAIL_ARROW_SIZE 34

  gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_int ("arrow-size",
                                                             "Arrow size",
                                                             "Size of the back button arrow",
                                                             0,
                                                             G_MAXINT,
                                                             _BREAD_CRUMB_TRAIL_ARROW_SIZE,
                                                             G_PARAM_READABLE));
  /* Signals */
  bread_crumb_trail_signals[CRUMB_CLICKED] =
    g_signal_new ("crumb-clicked",
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (HildonBreadCrumbTrailClass, crumb_clicked),
                  g_signal_accumulator_true_handled, NULL,
                  _hildon_marshal_BOOLEAN__POINTER,
                  G_TYPE_BOOLEAN, 1,
                  G_TYPE_POINTER);

  bread_crumb_trail_signals[MOVE_PARENT] =
    g_signal_new ("move-parent",
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (HildonBreadCrumbTrailClass, move_parent),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);
                  

  /* Binding set */
  binding_set = gtk_binding_set_by_class (widget_class);

  gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
                                "move-parent", 0);
  gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
                                "move-parent", 0);
                                
  /* Private data */
  g_type_class_add_private (gobject_class, sizeof (HildonBreadCrumbTrailPrivate));
}

static void
hildon_bread_crumb_trail_finalize (GObject *object)
{
  HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (object)->priv;

  g_list_free (priv->item_list);

  G_OBJECT_CLASS (hildon_bread_crumb_trail_parent_class)->finalize (object);
}

static void
hildon_bread_crumb_trail_move_parent (HildonBreadCrumbTrail *bct)
{
  if (g_list_length (bct->priv->item_list) > 1)
    {
      g_signal_emit_by_name (HILDON_BREAD_CRUMB (bct->priv->item_list->next->data),
                             "crumb-activated");
    }
}

static void
hildon_bread_crumb_trail_size_request (GtkWidget *widget,
                                       GtkRequisition *requisition)
{
  GList *p;
  GtkRequisition child_requisition;
  HildonBreadCrumbTrail *bct;
  HildonBreadCrumbTrailPrivate *priv;
  gint minimum_width, width = 0;
  PangoLayout *layout;
  gchar *tmp = NULL;

  bct= HILDON_BREAD_CRUMB_TRAIL (widget);
  priv = bct->priv;

  requisition->height = 0;
  requisition->width = 0;

  gtk_widget_size_request (priv->back_button, &child_requisition);
  requisition->width = child_requisition.width;
  requisition->height = child_requisition.height;

  if (priv->item_list)
    {
      /* Add minimum width for one item */
      /* TODO: this can be probably cached */
      gtk_widget_style_get (widget,
                            "minimum-width", &minimum_width,
                            NULL);

      tmp = g_strnfill ((gsize)minimum_width, 'm');
      layout = gtk_widget_create_pango_layout (widget, tmp);
      g_free (tmp);
      pango_layout_get_size (layout, &width, NULL);
      requisition->width += PANGO_PIXELS (width);
      g_object_unref (layout);
    }

  /* Button requisitions */
  for (p = priv->item_list; p; p = p->next)
    {
      GtkWidget *child = GTK_WIDGET (p->data);

      if (GTK_WIDGET_VISIBLE (child))
        gtk_widget_size_request (child, &child_requisition);
    }

  /* Border width */
  requisition->width += GTK_CONTAINER (widget)->border_width * 2;
  requisition->height += GTK_CONTAINER (widget)->border_width * 2;

  widget->requisition = *requisition;
}

/* Document me please */

static void
hildon_bread_crumb_trail_size_allocate (GtkWidget *widget,
                                        GtkAllocation *allocation)
{
  GtkRequisition req;
  gint natural_width, natural_height;
  HildonBreadCrumb *item;
  GtkAllocation child_allocation;
  GtkRequisition child_requisition;
  GtkWidget *child;
  gint allocation_width;
  gint border_width, width;
  gint extra_space;
  GList *p, *first_show, *first_hide;
  gint back_button_size;
  HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (widget)->priv;
  gboolean rtl;

  /* Get the rtl status */
  rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);

  widget->allocation = *allocation;

  border_width = (gint) GTK_CONTAINER (widget)->border_width;
  allocation_width = allocation->width - 2 * border_width;

  /* Allocate the back button */
  if (rtl)
    child_allocation.x = allocation->width - border_width;
  else
    child_allocation.x = allocation->x + border_width;

  child_allocation.y = allocation->y + border_width;
  gtk_widget_get_child_requisition (priv->back_button, &child_requisition);
  /* We want the back button to be a square */
  back_button_size = MAX (child_requisition.width, child_requisition.height);
  child_allocation.width = child_allocation.height = back_button_size;

  if (rtl)
    child_allocation.x -= back_button_size;

  gtk_widget_size_allocate (priv->back_button, &child_allocation);

  if (!rtl)
    child_allocation.x += back_button_size;

  /* If there are no buttons there's nothing else to do */
  if (priv->item_list == NULL)
    return;

  /* We find out how many buttons can we show, starting from the
     the last one in the logical path (the first item in the list) */

  width = back_button_size;
  p = priv->item_list;
  first_show = NULL;
  first_hide = NULL; 
  extra_space = 0;

  for (p = priv->item_list; p; p = p->next)
    {
      item = HILDON_BREAD_CRUMB (p->data);
      child = GTK_WIDGET (item);

      /* Does the widget fit with its natural size? */
      hildon_bread_crumb_get_natural_size (item,
                                           &natural_width,
                                           &natural_height);

      if (width + natural_width <= allocation_width)
        {
          /* Yes, it does */
          first_show = p;
          first_hide = p->next;
          width += natural_width;
        }
      else
        {
          /* No, it doesn't. Allocate as much as possible
             and stop */
          child_allocation.width = allocation_width - width;

          gtk_widget_size_request (child, &req);

          if (child_allocation.width > req.width)
            {
              first_hide = p->next;
              gtk_widget_set_child_visible (child, TRUE);

              if (rtl)
                child_allocation.x -= child_allocation.width;

              gtk_widget_size_allocate (child, &child_allocation);

              if (!rtl)
                child_allocation.x += child_allocation.width;
            }
          else
            {
              extra_space = child_allocation.width;
            }

          break;
        }
    }

  /* Not enough items to fill the breadcrumb? */
  if (p == NULL && width < allocation_width)
    {
      extra_space = allocation_width - width;
    }

  /* Allocate the other buttons */
  for (p = first_show; p; p = p->prev)
    {
      item = HILDON_BREAD_CRUMB (p->data);
      child = GTK_WIDGET (item);

      /* Does the widget fit with its natural size? */
      hildon_bread_crumb_get_natural_size (item,
                                           &natural_width,
                                           &natural_height);

      /* If I'm the last and there's extra space, use it */
      if (p->prev == NULL && extra_space != 0)
        {
          natural_width += extra_space;
        }

      child_allocation.width = natural_width;
      gtk_widget_set_child_visible (child, TRUE);

      if (rtl)
        child_allocation.x -= child_allocation.width;

      gtk_widget_size_allocate (child, &child_allocation);

      if (!rtl)
        child_allocation.x += child_allocation.width;
    }

  for (p = first_hide; p; p = p->next)
    {
      item = HILDON_BREAD_CRUMB (p->data);
      gtk_widget_set_child_visible (GTK_WIDGET (item), FALSE);
    }
}

static gpointer
get_bread_crumb_id (HildonBreadCrumb *item)
{
  return g_object_get_data (G_OBJECT (item), "bread-crumb-id");
}

static void
crumb_activated_cb (GtkWidget *button,
                    HildonBreadCrumbTrail *bct)
{
  gboolean signal_handled = FALSE;

  g_signal_emit (bct, bread_crumb_trail_signals[CRUMB_CLICKED], 0,
                 get_bread_crumb_id (HILDON_BREAD_CRUMB (button)),
                 &signal_handled);

  if (signal_handled == FALSE)
    {
      GtkWidget *child;
      gboolean focus_last_item = FALSE;
      HildonBreadCrumbTrailPrivate *priv;

      priv = bct->priv;

      child = GTK_WIDGET (priv->item_list->data);

      /* We remove the tip of the list until we hit the clicked button */
      while (child && child != button)
        {
          if (GTK_WIDGET_HAS_FOCUS (child))
            focus_last_item = TRUE;

          gtk_container_remove (GTK_CONTAINER (bct), child);

          if (priv->item_list == NULL)
              return;

          child = GTK_WIDGET (priv->item_list->data);
        }

      if (focus_last_item)
        gtk_widget_grab_focus (GTK_WIDGET (bct->priv->item_list->data));
    }
}

static void
hildon_bread_crumb_trail_add (GtkContainer *container,
                              GtkWidget *widget)
{
  gtk_widget_set_parent (widget, GTK_WIDGET (container));

  if (HILDON_IS_BREAD_CRUMB (widget))
    {
      HildonBreadCrumbTrail *bct = HILDON_BREAD_CRUMB_TRAIL (container);

      g_signal_connect (G_OBJECT (widget), "crumb-activated",
                        G_CALLBACK (crumb_activated_cb), container);

      bct->priv->item_list = g_list_prepend (bct->priv->item_list, widget);

      hildon_bread_crumb_trail_update_back_button_sensitivity (bct);
    }
}

static void
hildon_bread_crumb_trail_forall (GtkContainer *container,
                                 gboolean include_internals,
                                 GtkCallback callback,
                                 gpointer callback_data)
{
  g_return_if_fail (callback != NULL);
  g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (container));

  GList *children;
  HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (container)->priv;

  children = priv->item_list;

  while (children)
    {
      GtkWidget *child;
      child = GTK_WIDGET (children->data);
      children = children->next;

      (*callback) (child, callback_data);
    }

  if (include_internals && priv->back_button)
    {
      (*callback) (priv->back_button, callback_data);
    }
}

static void
hildon_bread_crumb_trail_remove (GtkContainer *container,
                                 GtkWidget *widget)
{
  GList *p, *next;
  HildonBreadCrumbTrailPrivate *priv;
  gboolean was_visible = GTK_WIDGET_VISIBLE (widget);

  priv = HILDON_BREAD_CRUMB_TRAIL (container)->priv;

  p = priv->item_list;

  while (p)
    {
      next = p->next;

      if (widget == GTK_WIDGET (p->data))
        {
          g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (crumb_activated_cb),
                                                HILDON_BREAD_CRUMB_TRAIL (container));
          gtk_widget_unparent (widget);

          priv->item_list = g_list_delete_link (priv->item_list, p);

          hildon_bread_crumb_trail_update_back_button_sensitivity (HILDON_BREAD_CRUMB_TRAIL (container));

          if (was_visible)
            {
              gtk_widget_queue_resize (GTK_WIDGET (container));
            }
        }

      p = next;
    }
}

static void
hildon_bread_crumb_trail_update_back_button_sensitivity (HildonBreadCrumbTrail *bct)
{
  guint list_length;
  HildonBreadCrumbTrailPrivate *priv = bct->priv;

  list_length = g_list_length (priv->item_list);

  if (list_length <= 1)
    {
      gtk_widget_set_sensitive (priv->back_button, FALSE);
    }
  else
    {
      gtk_widget_set_sensitive (priv->back_button, TRUE);
    }
}

static GtkWidget*
create_back_button (HildonBreadCrumbTrail *bct)
{
  GtkWidget *button;
  GtkWidget *arrow;
  gint arrow_size;

  gtk_widget_push_composite_child ();

  button = gtk_button_new ();
  gtk_widget_set_name (button, "hildon-bread-crumb-back-button");
  gtk_widget_set_sensitive (button, FALSE);

  arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
  bct->priv->arrow = arrow;
  gtk_widget_style_get (GTK_WIDGET (bct),
                        "arrow-size", &arrow_size,
                        NULL);
  gtk_widget_set_size_request (arrow, arrow_size, arrow_size);

  gtk_container_add (GTK_CONTAINER (button), arrow);
  gtk_container_add (GTK_CONTAINER (bct), button);
  gtk_widget_show_all (button);

  gtk_widget_pop_composite_child ();

  return button;
}

static void
hildon_bread_crumb_trail_init (HildonBreadCrumbTrail *bct)
{
  HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL_GET_PRIVATE (bct);

  GTK_WIDGET_SET_FLAGS (bct, GTK_NO_WINDOW);
  gtk_widget_set_redraw_on_allocate (GTK_WIDGET (bct), FALSE);

  bct->priv = priv;
  priv->item_list = NULL;

  priv->back_button = create_back_button (bct);
  g_signal_connect (priv->back_button, "clicked",
                    G_CALLBACK (hildon_bread_crumb_trail_scroll_back),
                    bct);
}

static void
hildon_bread_crumb_trail_scroll_back (GtkWidget *button,
                                      HildonBreadCrumbTrail *bct)
{
  hildon_bread_crumb_trail_move_parent (bct);
}

static void
attach_bread_crumb (HildonBreadCrumbTrail *bct,
                    GtkWidget *bread_crumb,
                    gpointer id,
                    GDestroyNotify destroy)
{
  g_object_set_data_full (G_OBJECT (bread_crumb), "bread-crumb-id", id, destroy);

  gtk_container_add (GTK_CONTAINER (bct), bread_crumb);

  gtk_widget_show (bread_crumb);
}

/* PUBLIC API */

/**
 * hildon_bread_crumb_trail_new:
 * 
 * Creates a new #HildonBreadCrumbTrail widget.
 *
 * Returns: a #GtkWidget pointer of newly created bread crumb trail
 * widget
 *
 * Stability: Unstable
 */

GtkWidget*
hildon_bread_crumb_trail_new (void)
{
  return GTK_WIDGET (g_object_new (HILDON_TYPE_BREAD_CRUMB_TRAIL, NULL));
}

/**
 * hildon_bread_crumb_trail_push:
 * @bct: pointer to #HildonBreadCrumbTrail
 * @item: the #HildonBreadCrumb to be added to the trail
 * @id: optional id for the bread crumb
 * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed
 *
 * Adds a new bread crumb to the end of the trail.
 *
 * Stability: Unstable
 */

void
hildon_bread_crumb_trail_push (HildonBreadCrumbTrail *bct,
                               HildonBreadCrumb *item,
                               gpointer id,
                               GDestroyNotify destroy)
{
  GtkWidget *widget;

  g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));
  g_return_if_fail (HILDON_IS_BREAD_CRUMB (item));

  widget = GTK_WIDGET (item);

  attach_bread_crumb (bct, widget, id, destroy);
}

/**
 * hildon_bread_crumb_trail_push_text:
 * @bct: pointer to #HildonBreadCrumbTrail
 * @text: content of the new bread crumb
 * @id: optional id for the bread crumb
 * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed
 *
 * Adds a new bread crumb to the end of the trail containing the specified text.
 *
 * Stability: Unstable
 */

void
hildon_bread_crumb_trail_push_text (HildonBreadCrumbTrail *bct,
                                    const gchar *text,
                                    gpointer id,
                                    GDestroyNotify destroy)
{
  GtkWidget *widget;

  g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));
  g_return_if_fail (text != NULL);

  widget = _hildon_bread_crumb_widget_new_with_text (text);
  if (bct->priv->item_list == NULL)
    {
      g_object_set (G_OBJECT (widget), "show-separator", FALSE, NULL);
    }
  attach_bread_crumb (bct, widget, id, destroy);
}

/**
 * hildon_bread_crumb_trail_push_icon:
 * @bct: pointer to #HildonBreadCrumbTrail
 * @text: content of the new bread crumb
 * @icon: a widget to set as the icon in the bread crumb
 * @id: optional id for the bread crumb
 * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed
 *
 * Adds a new bread crumb to the end of the trail containing the specified text and
 * icon.
 *
 * Stability: Unstable
 */

void
hildon_bread_crumb_trail_push_icon (HildonBreadCrumbTrail *bct,
                                    const gchar *text,
                                    GtkWidget *icon,
                                    gpointer id,
                                    GDestroyNotify destroy)
{
  GtkWidget *widget;

  g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));
  g_return_if_fail (text != NULL);
  g_return_if_fail (GTK_IS_WIDGET (icon));

  widget = _hildon_bread_crumb_widget_new_with_icon (icon, text);
  if (bct->priv->item_list == NULL)
    {
      g_object_set (G_OBJECT (widget), "show-separator", FALSE, NULL);
    }
  attach_bread_crumb (bct, widget, id, destroy);
}

/**
 * hildon_bread_crumb_trail_pop:
 * @bct: pointer to #HildonBreadCrumbTrail
 *
 * Removes the last bread crumb from the trail.
 *
 * Stability: Unstable
 */

void
hildon_bread_crumb_trail_pop (HildonBreadCrumbTrail *bct)
{
  GtkWidget *child;
  HildonBreadCrumbTrailPrivate *priv;

  g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));

  priv = bct->priv;

  if (priv->item_list == NULL)
    return;

  if (priv->item_list)
    {
      child = GTK_WIDGET (priv->item_list->data);
      gtk_container_remove (GTK_CONTAINER (bct), child);
    }

  hildon_bread_crumb_trail_update_back_button_sensitivity (bct);
}

/**
 * hildon_bread_crumb_trail_clear:
 * @bct: pointer to #HildonBreadCrumbTrail
 *
 * Removes all the bread crumbs from the bread crumb trail.
 *
 * Stability: Unstable
 */

void
hildon_bread_crumb_trail_clear (HildonBreadCrumbTrail *bct)
{
  HildonBreadCrumbTrailPrivate *priv;

  g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));

  priv = bct->priv;

  while (priv->item_list)
    {
      hildon_bread_crumb_trail_pop (bct);
    }

  /*
    Sensitivity hack from hell. We need to do this while
     http://bugzilla.gnome.org/show_bug.cgi?id=56070 is not
     fixed to allow repeated clicking on the back button if
     someone clears and rebuilds the trail when it's clicked
  */
  gtk_widget_hide (priv->back_button);
  gtk_widget_show (priv->back_button);
}