* stepmake/stepmake/metafont-rules.make: backport 1.7 fixes.
[lilypond.git] / lily / item.cc
blob77083104e06e4c2cf86f052592a52f263ccf5d77
1 /*
2 item.cc -- implement Item
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
10 #include "paper-score.hh"
11 #include "warn.hh"
12 #include "item.hh"
13 #include "paper-column.hh"
14 #include "spanner.hh"
15 #include "lily-guile.hh"
16 #include "system.hh"
17 #include "group-interface.hh"
19 Item::Item (SCM s)
20 : Grob (s)
22 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT]=0;
23 Group_interface::add_thing (this, ly_symbol2scm ("interfaces"), ly_symbol2scm ("item-interface"));
26 /**
27 Item copy ctor. Copy nothing: everything should be a elt property
28 or a special purpose pointer (such as broken_to_drul_[]) */
29 Item::Item (Item const &s)
30 : Grob (s)
32 broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] =0;
36 bool
37 Item::breakable_b (Grob*me)
39 if (me->original_)
40 return false;
42 if (!dynamic_cast<Item*> (me))
43 me->programming_error ("only items can be breakable.");
45 Item * i =dynamic_cast<Item*> (me->get_parent (X_AXIS));
46 return (i) ? Item::breakable_b (i) : to_boolean (me->get_grob_property ("breakable"));
49 Paper_column *
50 Item::get_column () const
52 Item *parent = dynamic_cast<Item*> (get_parent (X_AXIS));
53 return parent ? parent->get_column () : 0;
56 System *
57 Item::get_system () const
59 Grob *g = get_parent (X_AXIS);
60 return g ? g->get_system () : 0;
64 void
65 Item::copy_breakable_items ()
67 Drul_array<Item *> new_copies;
68 Direction i=LEFT;
69 do
71 Grob * dolly = clone ();
72 Item * item = dynamic_cast<Item*> (dolly);
73 pscore_->system_->typeset_grob (item);
74 new_copies[i] =item;
76 while (flip (&i) != LEFT);
77 broken_to_drul_= new_copies;
81 bool
82 Item::broken_b () const
84 return broken_to_drul_[LEFT] || broken_to_drul_[RIGHT];
89 Generate items for begin and end-of line.
91 void
92 Item::discretionary_processing ()
94 if (broken_b ())
95 return;
97 if (Item::breakable_b (this))
98 copy_breakable_items ();
101 Grob*
102 Item::find_broken_piece (System*l) const
104 if (get_system () == l)
105 return (Item*) (this);
107 Direction d = LEFT;
108 do {
109 Grob *s = broken_to_drul_[d];
110 if (s && s->get_system () == l)
111 return s;
113 while (flip (&d) != LEFT);
115 return 0;
119 Item*
120 Item::find_prebroken_piece (Direction d) const
122 Item * me = (Item *) (this);
123 if (!d)
124 return me;
125 return dynamic_cast<Item*> (broken_to_drul_[d]);
129 Direction
130 Item::break_status_dir () const
132 if (original_)
134 Item * i = dynamic_cast<Item*> (original_);
136 return (i->broken_to_drul_[LEFT] == this) ? LEFT : RIGHT;
138 else
139 return CENTER;
142 void
143 Item::handle_prebroken_dependencies ()
145 Grob::handle_prebroken_dependencies ();
148 Can't do this earlier, because try_visibility_lambda () might set
149 the elt property transparent, which would then be copied.
151 TODO:
153 give the item to break-visibility itself, so the function can do
154 more complicated things.
156 SCM vis = get_grob_property ("break-visibility");
157 if (gh_procedure_p (vis))
159 SCM args = scm_list_n (gh_int2scm (break_status_dir ()), SCM_UNDEFINED);
160 SCM result = gh_apply (vis, args);
161 bool trans = gh_scm2bool (ly_car (result));
162 bool empty = gh_scm2bool (ly_cdr (result));
164 if (empty && trans)
165 suicide ();
166 else if (empty)
168 set_extent (SCM_EOL, X_AXIS);
169 set_extent (SCM_EOL, Y_AXIS);
171 else if (trans)
172 set_grob_property ("molecule-callback", SCM_EOL);
177 Item::do_derived_mark ()const
179 if (broken_to_drul_[LEFT])
180 scm_gc_mark (broken_to_drul_[LEFT]->self_scm ());
181 if (broken_to_drul_[RIGHT])
182 scm_gc_mark (broken_to_drul_[RIGHT]->self_scm ());
183 return SCM_EOL;
186 Item*
187 unsmob_item (SCM s )
189 return dynamic_cast<Item*> (unsmob_grob (s));
194 ADD_INTERFACE(Item,
195 "item-interface",
198 Grobs can be distinguished in their role in the horizontal spacing.
199 Many grobs define constraints on the spacing by their sizes. For
200 example, note heads, clefs, stems, and all other symbols with a fixed
201 shape. These grobs form a subtype called @code{Item}.
204 "no-spacing-rods break-visibility breakable")