]> git.donarmstrong.com Git - lilypond.git/blob - lily/hara-kiri-group-spanner.cc
release: 1.3.131
[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--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7   Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9
10 #include "axis-group-interface.hh"
11 #include "spanner.hh"
12 #include "hara-kiri-group-spanner.hh"
13 #include "debug.hh"
14 #include "item.hh"
15
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) gh_scm2int (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
30 void
31 Hara_kiri_group_spanner::consider_suicide(Grob*me)
32 {
33   SCM worth = me->get_grob_property ("items-worth-living");
34   if (gh_pair_p (worth))
35     return ;
36
37   Link_array<Grob> childs = Axis_group_interface::get_children (me);
38   for (int i = 0; i < childs.size (); i++)
39     childs[i]->suicide ();
40
41
42   /*
43     very appropriate name here :-)
44    */
45   me->suicide ();
46 }
47
48
49
50 /*
51   We can't rely on offsets and dimensions of elements in a hara-kiri
52   group. Use a callback to make sure that hara-kiri has been done
53   before asking for offsets.  */
54 MAKE_SCHEME_CALLBACK(Hara_kiri_group_spanner,force_hara_kiri_callback,2);
55 SCM
56 Hara_kiri_group_spanner::force_hara_kiri_callback (SCM element_smob, SCM axis)
57 {
58   Grob *me = unsmob_grob (element_smob);
59   Axis a = (Axis) gh_scm2int (axis);
60   assert (a == Y_AXIS);
61   consider_suicide (me);
62   return gh_double2scm (0.0);
63 }
64
65
66 MAKE_SCHEME_CALLBACK(Hara_kiri_group_spanner,force_hara_kiri_in_parent_callback,2);
67 SCM
68 Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM element_smob, SCM axis)
69 {
70   Grob *daughter = unsmob_grob (element_smob);
71   Axis a = (Axis) gh_scm2int (axis);
72   assert (a == Y_AXIS);
73   force_hara_kiri_callback (daughter->parent_l (a)->self_scm (), axis);
74   return gh_double2scm ( 0.0);
75 }
76
77 void
78 Hara_kiri_group_spanner::add_element (Grob * me, Grob *e)
79 {
80   //  e->add_offset_callback (force_hara_kiri_in_parent_callback, Y_AXIS);
81   Axis_group_interface::add_element (me, e);
82 }
83
84
85 void
86 Hara_kiri_group_spanner::set_interface (Grob*me)
87 {
88   me->set_interface (ly_symbol2scm ("hara-kiri-group-interface"));
89 }
90
91
92 bool
93 Hara_kiri_group_spanner::has_interface (Grob*me)
94 {
95   return me->has_interface (ly_symbol2scm ("hara-kiri-group-interface"));
96 }
97
98 void 
99 Hara_kiri_group_spanner::add_interesting_item (Grob* me,Grob* n)
100 {
101   me->add_dependency (n);
102   Pointer_group_interface::add_element (me, "items-worth-living",n);
103 }