]> git.donarmstrong.com Git - lilypond.git/blob - lily/hara-kiri-group-spanner.cc
68164699672524d8fffa2473cf524a1475f03206
[lilypond.git] / lily / hara-kiri-group-spanner.cc
1 /*
2   hara-kiri-vertical-group-spanner.cc -- implement Hara_kiri_group_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7   Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
9
10 #include "hara-kiri-group-spanner.hh"
11
12 #include "paper-column.hh"
13 #include "pointer-group-interface.hh"
14 #include "axis-group-interface.hh"
15 #include "spanner.hh"
16 #include "warn.hh"
17 #include "item.hh"
18
19 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, y_extent, 1);
20 SCM
21 Hara_kiri_group_spanner::y_extent (SCM smob)
22 {
23   Grob *me = unsmob_grob (smob);
24   consider_suicide (me);
25   return Axis_group_interface::generic_group_extent (me, Y_AXIS);
26 }
27
28 void
29 Hara_kiri_group_spanner::consider_suicide (Grob *me)
30 {
31   Spanner *sp = dynamic_cast<Spanner *> (me);
32   if (!to_boolean (me->get_property ("remove-empty")))
33     return ;
34
35   extract_grob_set (me, "items-worth-living", worth);
36   if (worth.size ())
37     return;
38
39   bool remove_first = to_boolean (me->get_property ("remove-first"));
40   if (!remove_first
41        && ((sp->original () && broken_spanner_index (sp) == 0)
42            || Paper_column::get_rank (sp->get_bound (LEFT)->get_column ())
43            == 0)) 
44     return;
45
46   Link_array<Grob> childs;
47   Axis_group_interface::get_children (me, &childs);
48   for (int i = 0; i < childs.size (); i++)
49     childs[i]->suicide ();
50
51   /*
52     very appropriate name here :-)
53   */
54   me->suicide ();
55 }
56
57 /*
58   We can't rely on offsets and dimensions of elements in a hara-kiri
59   group. Use a callback to make sure that hara-kiri has been done
60   before asking for offsets.  */
61 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_callback, 2);
62 SCM
63 Hara_kiri_group_spanner::force_hara_kiri_callback (SCM smob, SCM axis)
64 {
65   Grob *me = unsmob_grob (smob);
66   (void) axis;
67
68   assert (scm_to_int (axis) == Y_AXIS);
69   consider_suicide (me);
70   return scm_from_double (0.0);
71 }
72
73 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_in_parent_callback, 2);
74 SCM
75 Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM smob, SCM axis)
76 {
77   Grob *daughter = unsmob_grob (smob);
78   Axis a = (Axis) scm_to_int (axis);
79   assert (a == Y_AXIS);
80   force_hara_kiri_callback (daughter->get_parent (a)->self_scm (), axis);
81   return scm_from_double (0.0);
82 }
83
84 void
85 Hara_kiri_group_spanner::add_interesting_item (Grob *me, Grob *n)
86 {
87   Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"), n);
88 }
89
90 ADD_INTERFACE (Hara_kiri_group_spanner, "hara-kiri-group-interface",
91                "A group spanner that  keeps track of interesting items.  If it "
92                "doesn't contain any after linebreaking, then it "
93                "will remove itself and all its children.",
94
95
96                /* properties */
97                "items-worth-living "
98                "remove-empty "
99                "remove-first "
100                );
101
102