]> git.donarmstrong.com Git - lilypond.git/blob - lily/separation-item.cc
24a87528b40407ddcedef4cefe3e3d1a2db3e478
[lilypond.git] / lily / separation-item.cc
1 /*   
2      separation-item.cc --  implement Separation_item
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "separation-item.hh"
11 #include "paper-column.hh"
12 #include "warn.hh"
13 #include "group-interface.hh"
14 #include "accidental-placement.hh"
15
16 void
17 Separation_item::add_item (Grob*s,Item* i)
18 {
19   assert (i);
20   Pointer_group_interface::add_grob (s, ly_symbol2scm ("elements"),i);
21   s->add_dependency (i);
22 }
23
24 void
25 Separation_item::add_conditional_item (Grob* me , Grob *e)
26 {
27   Pointer_group_interface::add_grob (me, ly_symbol2scm ("conditional-elements"), e);
28 }
29
30 /*
31   Return the width of ME given that we are considering the object on
32   the LEFT.
33  */
34 Interval
35 Separation_item::conditional_width (Grob * me, Grob * left)
36 {
37   Interval w = width (me);
38   
39   Item *item = dynamic_cast<Item*> (me);
40   Paper_column * pc = item->get_column ();
41   
42   
43   for (SCM s =  me->get_grob_property ("conditional-elements"); gh_pair_p (s); s = ly_cdr (s))
44     {
45       SCM elt = ly_car (s);
46       if (!unsmob_grob (elt))
47         continue;
48       
49       Item *il = unsmob_item (elt);
50       if (pc != il->get_column ())
51         {
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*/ 
55         }
56
57       if (to_boolean (il->get_grob_property ("no-spacing-rods")))
58         {
59           continue;
60         }
61
62       if (Accidental_placement::has_interface (il))
63         {
64           w.unite (Accidental_placement::get_relevant_accidental_extent (il, pc, left));
65         }
66     }
67
68   SCM pad = me->get_grob_property ("padding");
69
70   if (gh_number_p (pad))
71     {
72       w[RIGHT] += gh_scm2double (pad)/2;
73       w[LEFT] -= gh_scm2double (pad)/2;    
74     }
75   return w;
76 }
77
78 Interval
79 Separation_item::width (Grob *me)
80 {
81   SCM sw = me->get_grob_property ("X-extent");
82   if (ly_number_pair_p (sw))
83     {
84       return ly_scm2interval (sw);
85     }
86
87   Item *item = dynamic_cast<Item*> (me);
88   Paper_column * pc = item->get_column ();
89   Interval w;
90   
91   for (SCM s =  me->get_grob_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
92     {
93       SCM elt = ly_car (s);
94       if (!unsmob_grob (elt))
95         continue;
96
97       Item *il = unsmob_item (elt);
98       if (pc != il->get_column ())
99         {
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*/ 
103         }
104
105       if (to_boolean (il->get_grob_property ("no-spacing-rods")))
106         {
107           continue;
108         }
109
110       Interval iv (il->extent (pc, X_AXIS));
111       if (!iv.empty_b ())
112         {
113           w.unite (iv);
114         }
115     }
116
117   SCM pad = me->get_grob_property ("padding");
118
119   if (gh_number_p (pad))
120   {
121     w[RIGHT] += gh_scm2double (pad)/2;
122     w[LEFT] -= gh_scm2double (pad)/2;    
123   }
124
125   me->set_grob_property ("X-extent", ly_interval2scm (w));
126   
127   return w;
128 }
129
130
131
132
133
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");