]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/grob.hh
($(outdir)/%.pdf): add DVIPS_FLAGS. This will
[lilypond.git] / lily / include / grob.hh
1 /*
2   grob.hh -- declare Grob
3
4   source file of the LilyPond music typesetter
5   
6   (c) 1996--2004 Han-Wen Nienhuys
7 */
8
9 #ifndef GROB_HH
10 #define GROB_HH
11
12 #include "parray.hh"
13 #include "virtual-methods.hh"
14 #include "lily-guile.hh"
15 #include "lily-proto.hh"
16 #include "smobs.hh"
17 #include "dimension-cache.hh"
18 #include "grob-interface.hh"
19
20 /**
21     for administration of what was done already
22     */
23 enum Grob_status {
24   ORPHAN=0,                     // not yet added to Paper_score
25   VIRGIN,       
26   PRECALCING,
27   PRECALCED,            // calcs before spacing done
28   POSTCALCING,          // busy calculating. This is used to trap cyclic deps.
29   POSTCALCED,           // after spacing calcs done
30 };
31
32 typedef void (Grob::*Grob_method_pointer) (void);
33
34
35 #define get_grob_property(x) internal_get_grob_property(ly_symbol2scm(x))
36 #define set_grob_property(x,y) internal_set_grob_property(ly_symbol2scm(x),y)
37
38 /*
39    Basic output object.
40 */
41 class Grob  {
42 protected:
43   SCM immutable_property_alist_;
44   SCM mutable_property_alist_;
45   friend class Spanner;
46   
47   void substitute_mutable_properties(SCM,SCM);
48 public:
49   Grob *original_;
50
51   /**
52     Administration: Where are we?. This is mainly used by Super_element and
53     Grob::calcalute_dependencies ()
54
55     0 means ORPHAN,
56    */
57   char status_;
58
59
60   /*
61     IDEA: make this a global variable. This is the same for all
62     elements, I think it is safe to assume that we will not have
63     scores being formatted multithreadedly.
64    */
65   Paper_score *pscore_;
66   Dimension_cache dim_cache_[NO_AXES];
67
68   Grob (SCM basic_props);
69   Grob (Grob const&);
70   String name () const;
71   
72   /*
73     properties
74    */
75   SCM internal_get_grob_property (SCM) const;
76   void internal_set_grob_property (SCM, SCM val);
77   void add_to_list_property (SCM, SCM);
78   void warning (String)const;
79   void programming_error (String)const;
80   
81   void set_elt_pointer (const char*, SCM val);
82   friend class Property_engraver; //  UGHUGHUGH.
83   /*
84     related classes.
85    */
86   Paper_def *get_paper () const;
87
88   /**
89     add a dependency. It may be the 0 pointer, in which case, it is ignored.
90     */
91   void add_dependency (Grob*);    
92   virtual System * get_system () const;
93   bool linked_b () const;
94
95
96   VIRTUAL_COPY_CONS (Grob);
97  
98   /**
99      Recursively track all dependencies of this Grob.  The
100      status_ field is used as a mark-field.  It is marked with
101      #busy# during execution of this function, and marked with #final#
102      when finished.
103
104      #funcptr# is the function to call to update this element.
105    */
106   void calculate_dependencies (int final, int busy, SCM funcname);
107
108
109   virtual void do_break_processing ();
110   virtual Grob *find_broken_piece (System*) const;
111   virtual void discretionary_processing ();
112   virtual SCM do_derived_mark () const;
113
114   Stencil * get_stencil () const;
115   SCM get_uncached_stencil () const;
116
117   SCM get_property_alist_chain (SCM) const;
118   void suicide ();
119   bool live () const;
120   
121   DECLARE_SCHEME_CALLBACK (stencil_extent, (SCM smob, SCM axis));
122
123   static SCM ly_set_grob_property (SCM, SCM,SCM);
124   static SCM ly_get_grob_property (SCM, SCM);  
125
126   bool internal_has_interface (SCM intf);
127   static bool has_interface (Grob*me);  
128
129   virtual void handle_broken_dependencies ();
130   virtual void handle_prebroken_dependencies ();
131
132   DECLARE_SMOBS (Grob,foo);
133
134   void init ();
135 public:
136   bool is_empty (Axis a) const;
137
138   Interval extent (Grob * refpoint, Axis) const;
139  
140   void translate_axis (Real, Axis);
141   Real relative_coordinate (Grob const* refp, Axis) const;
142   Grob*common_refpoint (Grob const* s, Axis a) const;
143
144
145   // duh. slim down interface here. (todo)
146   bool has_offset_callback_b (SCM callback, Axis)const;
147   void add_offset_callback (SCM callback, Axis);
148   bool has_extent_callback_b (SCM, Axis)const;  
149   void set_extent (SCM , Axis);
150   Real get_offset (Axis a) const;
151   
152   void set_parent (Grob* e, Axis);
153   
154   Grob *get_parent (Axis a) const {   return  dim_cache_[a].parent_; }
155   DECLARE_SCHEME_CALLBACK (fixup_refpoint, (SCM));
156 };
157
158 DECLARE_UNSMOB(Grob,grob);
159 Spanner* unsmob_spanner (SCM );
160 Item* unsmob_item (SCM );
161
162 Grob*common_refpoint_of_list (SCM elt_list, Grob * , Axis a);
163 Grob*common_refpoint_of_array (Link_array<Grob> const&, Grob * , Axis a);
164
165 void set_break_subsititution (SCM criterion);
166 SCM substitute_mutable_property_alist (SCM alist);
167
168 Link_array<Grob> ly_scm2grobs (SCM l);
169 SCM ly_grobs2scm (Link_array<Grob> a);
170
171 #endif /* GROB_HH */
172