]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/grob.hh
* gcc-3.4 snapshot: 3.4.0 20040215 (prerelease) compile fixes, and
[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 /* Basic G[raphical output] O[bject].  */
36 class Grob
37 {
38 protected:
39   SCM immutable_property_alist_;
40   SCM mutable_property_alist_;
41   friend class Spanner;
42   
43   void substitute_mutable_properties(SCM,SCM);
44
45 public:
46   Grob *original_;
47
48   /**
49     Administration: Where are we?. This is mainly used by Super_element and
50     Grob::calcalute_dependencies ()
51
52     0 means ORPHAN,
53    */
54   char status_;
55
56
57   /*
58     IDEA: make this a global variable. This is the same for all
59     elements, I think it is safe to assume that we will not have
60     scores being formatted multithreadedly.
61    */
62   Paper_score *pscore_;
63   Dimension_cache dim_cache_[NO_AXES];
64
65   Grob (SCM basic_props);
66   Grob (Grob const&);
67   VIRTUAL_COPY_CONSTRUCTOR (Grob, Grob);
68  
69   String name () const;
70   
71   /*
72     properties
73    */
74   SCM internal_get_property (SCM) const;
75   void internal_set_property (SCM, SCM val);
76   void add_to_list_property (SCM, SCM);
77   void warning (String)const;
78   void programming_error (String)const;
79   
80   void set_elt_pointer (const char*, SCM val);
81   friend class Property_engraver; //  UGHUGHUGH.
82   /*
83     related classes.
84    */
85   Paper_def *get_paper () const;
86
87   /**
88     add a dependency. It may be the 0 pointer, in which case, it is ignored.
89     */
90   void add_dependency (Grob*);    
91   virtual System * get_system () const;
92
93   /**
94      Recursively track all dependencies of this Grob.  The
95      status_ field is used as a mark-field.  It is marked with
96      #busy# during execution of this function, and marked with #final#
97      when finished.
98
99      #funcptr# is the function to call to update this element.
100    */
101   void calculate_dependencies (int final, int busy, SCM funcname);
102
103
104   virtual void do_break_processing ();
105   virtual Grob *find_broken_piece (System*) const;
106   virtual void discretionary_processing ();
107   virtual SCM do_derived_mark () const;
108
109   Stencil * get_stencil () const;
110   SCM get_uncached_stencil () const;
111
112   SCM get_property_alist_chain (SCM) const;
113   void suicide ();
114   bool live () const;
115   
116   DECLARE_SCHEME_CALLBACK (stencil_extent, (SCM smob, SCM axis));
117
118   static SCM ly_grob_set_property (SCM, SCM,SCM);
119   static SCM ly_grob_property (SCM, SCM);  
120
121   bool internal_has_interface (SCM intf);
122   static bool has_interface (Grob*me);  
123
124   virtual void handle_broken_dependencies ();
125   virtual void handle_prebroken_dependencies ();
126
127   DECLARE_SMOBS (Grob,foo);
128
129   void init ();
130 public:
131   bool is_empty (Axis a) const;
132
133   Interval extent (Grob * refpoint, Axis) const;
134  
135   void translate_axis (Real, Axis);
136   Real relative_coordinate (Grob const* refp, Axis) const;
137   Grob*common_refpoint (Grob const* s, Axis a) const;
138
139
140   // duh. slim down interface here. (todo)
141   bool has_offset_callback (SCM callback, Axis)const;
142   void add_offset_callback (SCM callback, Axis);
143   bool has_extent_callback (SCM, Axis)const;  
144   void set_extent (SCM , Axis);
145   Real get_offset (Axis a) const;
146   
147   void set_parent (Grob* e, Axis);
148   
149   Grob *get_parent (Axis a) const {   return  dim_cache_[a].parent_; }
150   DECLARE_SCHEME_CALLBACK (fixup_refpoint, (SCM));
151 };
152
153 DECLARE_UNSMOB(Grob,grob);
154 Spanner* unsmob_spanner (SCM );
155 Item* unsmob_item (SCM );
156
157 Grob*common_refpoint_of_list (SCM elt_list, Grob * , Axis a);
158 Grob*common_refpoint_of_array (Link_array<Grob> const&, Grob * , Axis a);
159
160 void set_break_subsititution (SCM criterion);
161 SCM substitute_mutable_property_alist (SCM alist);
162
163 Link_array<Grob> ly_scm2grobs (SCM l);
164 SCM ly_grobs2scm (Link_array<Grob> a);
165
166 #endif /* GROB_HH */
167