release commit
[lilypond.git] / lily / separation-item.cc
blob24a87528b40407ddcedef4cefe3e3d1a2db3e478
1 /*
2 separation-item.cc -- implement Separation_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "separation-item.hh"
11 #include "paper-column.hh"
12 #include "warn.hh"
13 #include "group-interface.hh"
14 #include "accidental-placement.hh"
16 void
17 Separation_item::add_item (Grob*s,Item* i)
19 assert (i);
20 Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"),i);
21 s->add_dependency (i);
24 void
25 Separation_item::add_conditional_item (Grob* me , Grob *e)
27 Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
31 Return the width of ME given that we are considering the object on
32 the LEFT.
34 Interval
35 Separation_item::conditional_width (Grob * me, Grob * left)
37 Interval w = width (me);
39 Item *item = dynamic_cast<Item*> (me);
40 Paper_column * pc = item->get_column ();
43 for (SCM s = me->get_grob_property ("conditional-elements"); gh_pair_p (s); s = ly_cdr (s))
45 SCM elt = ly_car (s);
46 if (!unsmob_grob (elt))
47 continue;
49 Item *il = unsmob_item (elt);
50 if (pc != il->get_column ())
52 /* this shouldn't happen, but let's continue anyway. */
53 programming_error (_ ("Separation_item: I've been drinking too much"));
54 continue; /*UGH UGH*/
57 if (to_boolean (il->get_grob_property ("no-spacing-rods")))
59 continue;
62 if (Accidental_placement::has_interface (il))
64 w.unite (Accidental_placement::get_relevant_accidental_extent (il, pc, left));
68 SCM pad = me->get_grob_property ("padding");
70 if (gh_number_p (pad))
72 w[RIGHT] += gh_scm2double (pad)/2;
73 w[LEFT] -= gh_scm2double (pad)/2;
75 return w;
78 Interval
79 Separation_item::width (Grob *me)
81 SCM sw = me->get_grob_property ("X-extent");
82 if (ly_number_pair_p (sw))
84 return ly_scm2interval (sw);
87 Item *item = dynamic_cast<Item*> (me);
88 Paper_column * pc = item->get_column ();
89 Interval w;
91 for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
93 SCM elt = ly_car (s);
94 if (!unsmob_grob (elt))
95 continue;
97 Item *il = unsmob_item (elt);
98 if (pc != il->get_column ())
100 /* this shouldn't happen, but let's continue anyway. */
101 programming_error (_ ("Separation_item: I've been drinking too much"));
102 continue; /*UGH UGH*/
105 if (to_boolean (il->get_grob_property ("no-spacing-rods")))
107 continue;
110 Interval iv (il->extent (pc, X_AXIS));
111 if (!iv.empty_b ())
113 w.unite (iv);
117 SCM pad = me->get_grob_property ("padding");
119 if (gh_number_p (pad))
121 w[RIGHT] += gh_scm2double (pad)/2;
122 w[LEFT] -= gh_scm2double (pad)/2;
125 me->set_grob_property ("X-extent", ly_interval2scm (w));
127 return w;
134 ADD_INTERFACE (Separation_item,"separation-item-interface",
135 "Item that computes widths to generate spacing rods.\n"
136 "\n"
137 "Calculate dimensions for the Separating_group_spanner; this has to be "
138 "an item to get dependencies correct. "
139 , "padding X-extent conditional-elements elements");