]> git.donarmstrong.com Git - lilypond.git/blob - lily/hara-kiri-group-spanner.cc
2003 -> 2004
[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--2004 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   Spanner*sp = dynamic_cast<Spanner*> (me);
34   SCM worth = me->get_grob_property ("items-worth-living");
35   if (gh_pair_p (worth))
36     return ;
37
38   if (!to_boolean (me->get_grob_property ("remove-first"))
39       && broken_spanner_index (sp) == 0)
40     {
41       return ;
42     }
43   
44   Link_array<Grob> childs = Axis_group_interface::get_children (me);
45   for (int i = 0; i < childs.size (); i++)
46     childs[i]->suicide ();
47
48
49   /*
50     very appropriate name here :-)
51    */
52   me->suicide ();
53 }
54
55
56
57 /*
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)
64 {
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);
70 }
71
72
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)
76 {
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);
82 }
83
84 void
85 Hara_kiri_group_spanner::add_element (Grob * me, Grob *e)
86 {
87   //  e->add_offset_callback (force_hara_kiri_in_parent_callback, Y_AXIS);
88   Axis_group_interface::add_element (me, e);
89 }
90
91
92
93
94
95 void 
96 Hara_kiri_group_spanner::add_interesting_item (Grob* me,Grob* n)
97 {
98   me->add_dependency (n);
99   Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"),n);
100 }
101
102
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");
109