(Which properties to
[lilypond.git] / lily / hara-kiri-group-spanner.cc
blobdabcf7c7e186d054dbb6d5fb76496acfc04d6118
1 /*
2 hara-kiri-vertical-group-spanner.cc -- implement Hara_kiri_group_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "axis-group-interface.hh"
11 #include "spanner.hh"
12 #include "hara-kiri-group-spanner.hh"
13 #include "warn.hh"
14 #include "item.hh"
17 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner,y_extent,2);
18 SCM
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);
24 assert (a == Y_AXIS);
25 consider_suicide (me);
26 return Axis_group_interface::group_extent_callback (me->self_scm (), scm_axis);
30 void
31 Hara_kiri_group_spanner::consider_suicide (Grob*me)
33 Spanner*sp = dynamic_cast<Spanner*> (me);
34 SCM worth = me->get_property ("items-worth-living");
35 if (gh_pair_p (worth))
36 return ;
38 if (!to_boolean (me->get_property ("remove-first"))
39 && broken_spanner_index (sp) == 0)
41 return ;
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 :-)
52 me->suicide ();
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 element_smob, SCM axis)
65 Grob *me = unsmob_grob (element_smob);
66 Axis a = (Axis) gh_scm2int (axis);
67 assert (a == Y_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);
74 SCM
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);
79 assert (a == Y_AXIS);
80 force_hara_kiri_callback (daughter->get_parent (a)->self_scm (), axis);
81 return gh_double2scm (0.0);
84 void
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);
95 void
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 "A group spanner that keeps track of interesting items. If it "
105 "doesn't contain any after linebreaking, then it "
106 "will remove itself and all its children."
108 "items-worth-living remove-first");