]> git.donarmstrong.com Git - lilypond.git/blob - lily/hara-kiri-group-spanner.cc
*** empty log message ***
[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--2003 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 "warn.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->get_parent (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
86
87
88 void 
89 Hara_kiri_group_spanner::add_interesting_item (Grob* me,Grob* n)
90 {
91   me->add_dependency (n);
92   Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"),n);
93 }
94
95
96 ADD_INTERFACE (Hara_kiri_group_spanner,"hara-kiri-group-interface",
97   "  As Vertical_group_spanner, but keep track of interesting items.  If        \
98 we don't contain any interesting items after linebreaking, then                 \
99 gracefully commit suicide.  Objective: don't disgrace Lily by                   \
100 typesetting empty lines in orchestral scores.",                                 \
101   "items-worth-living");
102