]> git.donarmstrong.com Git - lilypond.git/blob - lily/hara-kiri-group-spanner.cc
* flower
[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 "axis-group-interface.hh"
13 #include "spanner.hh"
14 #include "warn.hh"
15 #include "item.hh"
16
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)
20 {
21   Grob *me = unsmob_grob (element_smob);
22   Axis a = (Axis) scm_to_int (scm_axis);
23
24   assert (a == Y_AXIS);
25   consider_suicide (me);
26   return Axis_group_interface::group_extent_callback (me->self_scm (), scm_axis);
27 }
28
29 void
30 Hara_kiri_group_spanner::consider_suicide (Grob *me)
31 {
32   Spanner *sp = dynamic_cast<Spanner *> (me);
33   SCM worth = me->get_property ("items-worth-living");
34   if (scm_is_pair (worth))
35     return;
36
37   if (!to_boolean (me->get_property ("remove-first"))
38       && broken_spanner_index (sp) == 0)
39     {
40       return;
41     }
42
43   Link_array<Grob> childs = Axis_group_interface::get_children (me);
44   for (int i = 0; i < childs.size (); i++)
45     childs[i]->suicide ();
46
47   /*
48     very appropriate name here :-)
49   */
50   me->suicide ();
51 }
52
53 /*
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);
58 SCM
59 Hara_kiri_group_spanner::force_hara_kiri_callback (SCM element_smob, SCM axis)
60 {
61   Grob *me = unsmob_grob (element_smob);
62   Axis a = (Axis) scm_to_int (axis);
63   assert (a == Y_AXIS);
64   consider_suicide (me);
65   return scm_make_real (0.0);
66 }
67
68 MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_in_parent_callback, 2);
69 SCM
70 Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM element_smob, SCM axis)
71 {
72   Grob *daughter = unsmob_grob (element_smob);
73   Axis a = (Axis) scm_to_int (axis);
74   assert (a == Y_AXIS);
75   force_hara_kiri_callback (daughter->get_parent (a)->self_scm (), axis);
76   return scm_make_real (0.0);
77 }
78
79 void
80 Hara_kiri_group_spanner::add_element (Grob *me, Grob *e)
81 {
82   //  e->add_offset_callback (force_hara_kiri_in_parent_callback, Y_AXIS);
83   Axis_group_interface::add_element (me, e);
84 }
85
86
87 void
88 Hara_kiri_group_spanner::add_interesting_item (Grob *me, Grob *n)
89 {
90   me->add_dependency (n);
91   Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"), n);
92 }
93
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");
99