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