]> git.donarmstrong.com Git - lilypond.git/blob - lily/item.cc
release: 1.3.51
[lilypond.git] / lily / item.cc
1 /*
2   item.cc -- implement Item
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "dimension-cache.hh"
10 #include "paper-score.hh"
11 #include "debug.hh"
12 #include "item.hh"
13 #include "paper-column.hh"
14 #include "spanner.hh"
15 #include "lily-guile.hh"
16 #include "line-of-score.hh"
17
18 Item::Item ()
19 {
20   broken_to_drul_[LEFT] = broken_to_drul_[RIGHT]=0;
21 }
22
23 /**
24    Item copy ctor.  Copy nothing: everything should be a elt property
25    or a special purpose pointer (such as broken_to_drul_[]) */
26 Item::Item (Item const &s)
27   : Score_element (s)
28 {
29   broken_to_drul_[LEFT] = broken_to_drul_[RIGHT] =0;
30 }
31
32
33
34 bool
35 Item::breakable_b () const
36 {
37   if (original_l_ )
38     return false;
39   
40   Item * i  =dynamic_cast<Item*> (parent_l (X_AXIS));
41   return (i) ?  i->breakable_b () : to_boolean (get_elt_property ("breakable"));
42 }
43
44 Line_of_score *
45 Item::line_l() const
46 {
47   Score_element *g = parent_l (X_AXIS);
48   return g ?  g->line_l () : 0;
49 }
50
51
52 void
53 Item::copy_breakable_items()
54 {
55   Drul_array<Item *> new_copies;
56   Direction  i=LEFT;
57   do 
58     {
59       Score_element * dolly = clone();
60       Item * item_p = dynamic_cast<Item*>(dolly);
61       pscore_l_->line_l_->typeset_element (item_p);
62       new_copies[i] =item_p;
63     }
64   while (flip(&i) != LEFT);
65   broken_to_drul_= new_copies;
66 }
67
68
69 bool
70 Item::broken_b () const
71 {
72   return broken_to_drul_[LEFT] || broken_to_drul_[RIGHT];
73 }
74
75 void
76 Item::do_breakable_col_processing()
77 {
78   if (broken_b ())
79     return;
80
81   if (breakable_b ())
82     copy_breakable_items();
83 }
84
85 Score_element*
86 Item::find_broken_piece (Line_of_score*l) const
87 {
88   if (line_l() == l) 
89     return (Item*)(this);
90
91   Direction d = LEFT;
92   do {
93     Score_element *s = broken_to_drul_[d];
94     if (s && s->line_l () == l)
95       return s;
96   }
97   while (flip (&d) != LEFT);
98
99   return 0;
100 }
101
102
103 Item*
104 Item::find_prebroken_piece (Direction d) const
105 {
106   Item * me = (Item *) (this);  
107   if (!d)
108     return me;
109   return dynamic_cast<Item*> (broken_to_drul_[d]);
110 }
111
112 Paper_column *
113 Item::column_l () const
114 {
115   return dynamic_cast<Item*> (parent_l (X_AXIS))->column_l ();
116 }
117
118 Direction
119 Item::break_status_dir () const
120 {
121   if (original_l_)
122     {
123       Item * i = dynamic_cast<Item*> (original_l_);
124
125       return (i->broken_to_drul_[LEFT] == this) ? LEFT : RIGHT;
126     }
127   else
128     return CENTER;
129 }
130
131 void
132 Item::handle_prebroken_dependencies ()
133 {
134   if (original_l_)
135     {
136       element_property_alist_
137         = handle_broken_smobs (original_l_->element_property_alist_,
138                                gh_int2scm (break_status_dir ()));
139     }
140   
141   /*
142     Can't do this earlier, because try_visibility_lambda () might set
143     the elt property transparent, which would then be copied.
144   */
145   SCM vis = remove_elt_property ("visibility-lambda");
146   if (gh_procedure_p (vis))
147     {
148       SCM args = scm_listify (gh_int2scm (break_status_dir ()), SCM_UNDEFINED);
149       SCM result = gh_apply (vis, args);
150       bool trans = gh_scm2bool (gh_car (result));
151       bool empty = gh_scm2bool (gh_cdr (result));
152
153       if (empty)
154         {
155           set_extent_callback (0, X_AXIS);
156           set_extent_callback (0,  Y_AXIS);
157         }
158       if (trans)
159         set_elt_property ("transparent", SCM_BOOL_T);
160     }
161 }