(parse_symbol_list): Bugfix.
[lilypond/patrick.git] / lily / axis-group-interface.cc
blob3d6889c6ac3d9c828f57d6ba745756917c574cdf
1 /*
2 axis-group-interface.cc -- implement Axis_group_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "axis-group-interface.hh"
11 #include "pointer-group-interface.hh"
12 #include "grob.hh"
13 #include "hara-kiri-group-spanner.hh"
14 #include "warn.hh"
16 void
17 Axis_group_interface::add_element (Grob *me, Grob *e)
19 SCM axes = me->get_property ("axes");
20 if (!scm_is_pair (axes))
21 programming_error ("axes should be nonempty");
23 for (SCM ax = axes; ax != SCM_EOL; ax = scm_cdr (ax))
25 Axis a = (Axis) scm_to_int (scm_car (ax));
27 if (!e->get_parent (a))
28 e->set_parent (me, a);
30 e->internal_set_object ((a == X_AXIS)
31 ? ly_symbol2scm ("axis-group-parent-X")
32 : ly_symbol2scm ("axis-group-parent-Y"),
33 me->self_scm ());
36 Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
39 bool
40 Axis_group_interface::has_axis (Grob *me, Axis a)
43 urg. FIXME, check for Hara_kiri_group_spanner shouldn't be necessary?
45 return me->has_extent_callback (group_extent_callback_proc, a)
46 || (me->has_extent_callback (Hara_kiri_group_spanner::y_extent_proc, a));
49 Interval
50 Axis_group_interface::relative_group_extent (Link_array<Grob> const &elts,
51 Grob *common, Axis a)
53 Interval r;
54 for (int i = 0; i < elts.size (); i++)
56 Grob *se = elts[i];
57 Interval dims = se->extent (common, a);
58 if (!dims.is_empty ())
59 r.unite (dims);
61 return r;
65 MAKE_SCHEME_CALLBACK (Axis_group_interface, group_extent_callback, 2);
66 SCM
67 Axis_group_interface::group_extent_callback (SCM element_smob, SCM scm_axis)
69 Grob *me = unsmob_grob (element_smob);
70 Axis a = (Axis) scm_to_int (scm_axis);
72 extract_grob_set (me, "elements", elts);
73 Grob *common = common_refpoint_of_array (elts, me, a);
75 Real my_coord = me->relative_coordinate (common, a);
76 Interval r (relative_group_extent (elts, common, a));
78 return ly_interval2scm (r - my_coord);
81 void
82 Axis_group_interface::set_axes (Grob *me, Axis a1, Axis a2)
84 SCM sa1 = scm_from_int (a1);
85 SCM sa2 = scm_from_int (a2);
87 SCM axes = me->get_property ("axes");
89 if (!scm_is_pair (axes)
90 || scm_c_memq (sa1, axes) == SCM_BOOL_F
91 || scm_c_memq (sa2, axes) == SCM_BOOL_F)
93 SCM ax = scm_cons (sa1, SCM_EOL);
94 if (a1 != a2)
95 ax = scm_cons (sa2, ax);
96 me->set_property ("axes", ax);
99 if (a1 != X_AXIS && a2 != X_AXIS)
100 me->set_extent (SCM_EOL, X_AXIS);
101 if (a1 != Y_AXIS && a2 != Y_AXIS)
102 me->set_extent (SCM_EOL, Y_AXIS);
105 why so convoluted ? (fixme/documentme?)
107 if (me->has_extent_callback (Grob::stencil_extent_proc, a1))
108 me->set_extent_callback (Axis_group_interface::group_extent_callback_proc, a1);
109 if (me->has_extent_callback (Grob::stencil_extent_proc, a2))
110 me->set_extent_callback (Axis_group_interface::group_extent_callback_proc, a2);
113 void
114 Axis_group_interface::get_children (Grob *me, Link_array<Grob> *found)
116 found->push (me);
118 if (!has_interface (me))
119 return;
121 extract_grob_set (me, "elements", elements);
122 for (int i = 0; i < elements.size (); i++)
124 Grob *e = elements[i];
125 Axis_group_interface::get_children (e, found);
129 ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
130 "An object that groups other layout objects.",
131 "axes elements");