2 hara-kiri-vertical-group-spanner.cc -- implement Hara_kiri_group_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "axis-group-interface.hh"
12 #include "hara-kiri-group-spanner.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);
22 Axis a = (Axis) gh_scm2int (scm_axis);
25 consider_suicide (me);
26 return Axis_group_interface::group_extent_callback (me->self_scm (), scm_axis);
31 Hara_kiri_group_spanner::consider_suicide (Grob*me)
33 Spanner*sp = dynamic_cast<Spanner*> (me);
34 SCM worth = me->get_grob_property ("items-worth-living");
35 if (gh_pair_p (worth))
38 if (!to_boolean (me->get_grob_property ("remove-first"))
39 && broken_spanner_index (sp) == 0)
44 Link_array<Grob> childs = Axis_group_interface::get_children (me);
45 for (int i = 0; i < childs.size (); i++)
46 childs[i]->suicide ();
50 very appropriate name here :-)
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);
63 Hara_kiri_group_spanner::force_hara_kiri_callback (SCM element_smob, SCM axis)
65 Grob *me = unsmob_grob (element_smob);
66 Axis a = (Axis) gh_scm2int (axis);
68 consider_suicide (me);
69 return gh_double2scm (0.0);
73 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner,force_hara_kiri_in_parent_callback,2);
75 Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM element_smob, SCM axis)
77 Grob *daughter = unsmob_grob (element_smob);
78 Axis a = (Axis) gh_scm2int (axis);
80 force_hara_kiri_callback (daughter->get_parent (a)->self_scm (), axis);
81 return gh_double2scm (0.0);
85 Hara_kiri_group_spanner::add_element (Grob * me, Grob *e)
87 // e->add_offset_callback (force_hara_kiri_in_parent_callback, Y_AXIS);
88 Axis_group_interface::add_element (me, e);
96 Hara_kiri_group_spanner::add_interesting_item (Grob* me,Grob* n)
98 me->add_dependency (n);
99 Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"),n);
103 ADD_INTERFACE (Hara_kiri_group_spanner,"hara-kiri-group-interface",
104 " As Vertical_group_spanner, but keep track of interesting items. If \
105 we don't contain any interesting items after linebreaking, then \
106 gracefully commit suicide. Objective: don't disgrace Lily by \
107 typesetting empty lines in orchestral scores.", \
108 "items-worth-living remove-first");