]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-interface.cc
Update using bison-CVS.
[lilypond.git] / lily / axis-group-interface.cc
1 /*
2   axis-group-interface.cc -- implement Axis_group_interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "axis-group-interface.hh"
10 #include "hara-kiri-group-spanner.hh"
11
12 void
13 Axis_group_interface::add_element (Grob *me, Grob *e)
14 {
15   for (SCM ax = me->get_property ("axes"); ax != SCM_EOL; ax = scm_cdr (ax))
16     {
17       Axis a = (Axis) scm_to_int (scm_car (ax));
18
19       if (!e->get_parent (a))
20         e->set_parent (me, a);
21
22       e->internal_set_property ((a == X_AXIS)
23                                 ? ly_symbol2scm ("axis-group-parent-X")
24                                 : ly_symbol2scm ("axis-group-parent-Y"),
25                                 me->self_scm ());
26     }
27
28   Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), e);
29   me->add_dependency (e);
30 }
31
32 bool
33 Axis_group_interface::has_axis (Grob *me, Axis a)
34 {
35   /*
36     urg. FIXME, check for Hara_kiri_group_spanner shouldn't be necessary?
37   */
38   return me->has_extent_callback (group_extent_callback_proc, a)
39     || (me->has_extent_callback (Hara_kiri_group_spanner::y_extent_proc, a));
40 }
41
42 Interval
43 Axis_group_interface::relative_group_extent (Axis a, Grob *common, SCM elts)
44 {
45   Interval r;
46   for (SCM s = elts; scm_is_pair (s); s = scm_cdr (s))
47     {
48       Grob *se = unsmob_grob (scm_car (s));
49       Interval dims = se->extent (common, a);
50       if (!dims.is_empty ())
51         r.unite (dims);
52     }
53   return r;
54 }
55
56 MAKE_SCHEME_CALLBACK (Axis_group_interface, group_extent_callback, 2);
57 SCM
58 Axis_group_interface::group_extent_callback (SCM element_smob, SCM scm_axis)
59 {
60   Grob *me = unsmob_grob (element_smob);
61   Axis a = (Axis) scm_to_int (scm_axis);
62
63   SCM elts = me->get_property ("elements");
64   Grob *common = common_refpoint_of_list (elts, me, a);
65
66   Real my_coord = me->relative_coordinate (common, a);
67   Interval r (relative_group_extent (a, common, elts));
68
69   return ly_interval2scm (r - my_coord);
70 }
71
72 void
73 Axis_group_interface::set_axes (Grob *me, Axis a1, Axis a2)
74 {
75   SCM sa1 = scm_int2num (a1);
76   SCM sa2 = scm_int2num (a2);
77
78   SCM axes = me->get_property ("axes");
79
80   if (!scm_is_pair (axes)
81       || scm_c_memq (sa1, axes) == SCM_BOOL_F
82       || scm_c_memq (sa2, axes) == SCM_BOOL_F)
83     {
84       SCM ax = scm_cons (sa1, SCM_EOL);
85       if (a1 != a2)
86         ax = scm_cons (sa2, ax);
87       me->set_property ("axes", ax);
88     }
89
90   if (a1 != X_AXIS && a2 != X_AXIS)
91     me->set_extent (SCM_EOL, X_AXIS);
92   if (a1 != Y_AXIS && a2 != Y_AXIS)
93     me->set_extent (SCM_EOL, Y_AXIS);
94
95   /*
96     why so convoluted ? (fixme/documentme?)
97   */
98   if (me->has_extent_callback (Grob::stencil_extent_proc, a1))
99     me->set_extent_callback (Axis_group_interface::group_extent_callback_proc, a1);
100   if (me->has_extent_callback (Grob::stencil_extent_proc, a2))
101     me->set_extent_callback (Axis_group_interface::group_extent_callback_proc, a2);
102 }
103
104 Link_array<Grob>
105 Axis_group_interface::get_children (Grob *me)
106 {
107   Link_array<Grob> childs;
108   childs.push (me);
109
110   if (!has_interface (me))
111     return childs;
112
113   for (SCM ep = me->get_property ("elements"); scm_is_pair (ep); ep = scm_cdr (ep))
114     {
115       Grob *e = unsmob_grob (scm_car (ep));
116       if (e)
117         childs.concat (Axis_group_interface::get_children (e));
118     }
119
120   return childs;
121 }
122
123 ADD_INTERFACE (Axis_group_interface, "axis-group-interface",
124                "An object that groups other layout objects.",
125                "axes elements");