2 hara-kiri-vertical-group-spanner.cc -- implement Hara_kiri_group_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "hara-kiri-group-spanner.hh"
12 #include "axis-group-interface.hh"
17 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, y_extent, 2);
19 Hara_kiri_group_spanner::y_extent (SCM element_smob, SCM scm_axis)
21 Grob *me = unsmob_grob (element_smob);
24 assert (scm_to_int (scm_axis) == Y_AXIS);
25 consider_suicide (me);
26 return Axis_group_interface::group_extent_callback (me->self_scm (), scm_axis);
30 Hara_kiri_group_spanner::consider_suicide (Grob *me)
32 Spanner *sp = dynamic_cast<Spanner *> (me);
33 SCM worth = me->get_property ("items-worth-living");
34 if (scm_is_pair (worth))
37 if (!to_boolean (me->get_property ("remove-first"))
38 && broken_spanner_index (sp) == 0)
43 Link_array<Grob> childs = Axis_group_interface::get_children (me);
44 for (int i = 0; i < childs.size (); i++)
45 childs[i]->suicide ();
48 very appropriate name here :-)
54 We can't rely on offsets and dimensions of elements in a hara-kiri
55 group. Use a callback to make sure that hara-kiri has been done
56 before asking for offsets. */
57 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_callback, 2);
59 Hara_kiri_group_spanner::force_hara_kiri_callback (SCM element_smob, SCM axis)
61 Grob *me = unsmob_grob (element_smob);
64 assert (scm_to_int (axis) == Y_AXIS);
65 consider_suicide (me);
66 return scm_make_real (0.0);
69 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_in_parent_callback, 2);
71 Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM element_smob, SCM axis)
73 Grob *daughter = unsmob_grob (element_smob);
74 Axis a = (Axis) scm_to_int (axis);
76 force_hara_kiri_callback (daughter->get_parent (a)->self_scm (), axis);
77 return scm_make_real (0.0);
81 Hara_kiri_group_spanner::add_element (Grob *me, Grob *e)
83 // e->add_offset_callback (force_hara_kiri_in_parent_callback, Y_AXIS);
84 Axis_group_interface::add_element (me, e);
88 Hara_kiri_group_spanner::add_interesting_item (Grob *me, Grob *n)
90 me->add_dependency (n);
91 Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"), n);
94 ADD_INTERFACE (Hara_kiri_group_spanner, "hara-kiri-group-interface",
95 "A group spanner that keeps track of interesting items. If it "
96 "doesn't contain any after linebreaking, then it "
97 "will remove itself and all its children.",
98 "items-worth-living remove-first");