]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/grob.hh
eee95e9b98bc0b2ca35c3a021235c6dcc7c91cbc
[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--2006 Han-Wen Nienhuys
7 */
8
9 #ifndef GROB_HH
10 #define GROB_HH
11
12 #include "virtual-methods.hh"
13 #include "dimension-cache.hh"
14 #include "grob-interface.hh"
15 #include "object-key.hh"
16
17 class Grob
18 {
19 private:
20   DECLARE_SMOBS (Grob, foo);
21   DECLARE_CLASSNAME(Grob);
22   
23   void init ();
24
25 protected:
26   /* data */
27   Dimension_cache dim_cache_[NO_AXES];
28   Output_def *layout_;
29   Grob *original_;
30   Object_key const *key_;
31
32   /* SCM data */
33   SCM immutable_property_alist_;
34   SCM mutable_property_alist_;
35   SCM object_alist_;
36   
37   /*
38     If this is a property, it accounts for 25% of the property
39     lookups.
40   */
41   SCM interfaces_;
42   
43   void substitute_object_links (SCM, SCM);
44   Real get_offset (Axis a) const;
45   SCM try_callback (SCM, SCM);
46 public:
47   
48   /* friends */
49   friend class Spanner;
50   friend class System;
51   friend SCM ly_grob_properties (SCM);
52   friend SCM ly_grob_basic_properties (SCM);
53
54   /* standard callbacks */
55   DECLARE_SCHEME_CALLBACK(x_parent_positioning, (SCM));
56   DECLARE_SCHEME_CALLBACK(y_parent_positioning, (SCM));
57   DECLARE_SCHEME_CALLBACK (stencil_height, (SCM smob));
58   DECLARE_SCHEME_CALLBACK (stencil_width, (SCM smob));
59
60   /* R/O access */
61   Output_def *layout () const { return layout_; }
62   Grob *original () const { return original_; }
63   SCM interfaces () const { return interfaces_; }
64   Object_key const *key () const { return key_; }
65
66   /* life & death */ 
67   Grob (SCM basic_props, Object_key const *);
68   Grob (Grob const &, int copy_count);
69   virtual Grob *clone (int count) const;
70
71   /* forced death */
72   void suicide ();
73   bool is_live () const;
74
75   /* naming. */
76   string name () const;
77
78   /* Properties */
79   SCM get_property_alist_chain (SCM) const;
80   SCM internal_get_property (SCM symbol) const;
81   SCM get_property_data (SCM symbol) const;
82   SCM internal_get_object (SCM symbol) const;
83   void internal_set_object (SCM sym, SCM val);
84   void internal_del_property (SCM symbol);
85
86 #ifndef NDEBUG
87   void internal_set_property (SCM sym, SCM val, char const *file, int line, char const *fun);
88 #else
89   void internal_set_property (SCM sym, SCM val);
90 #endif
91
92   /* messages */  
93   void warning (string) const;
94   void programming_error (string) const;
95
96
97   /* class hierarchy */
98   virtual System *get_system () const;
99   virtual void do_break_processing ();
100   virtual Grob *find_broken_piece (System *) const;
101   virtual void discretionary_processing ();
102   virtual void derived_mark () const;
103   virtual void handle_broken_dependencies ();
104   virtual void handle_prebroken_dependencies ();
105
106   /* printing */
107   Stencil *get_stencil () const;
108   Stencil get_print_stencil () const;
109
110   /* interfaces */
111   bool internal_has_interface (SCM intf);
112   static bool has_interface (Grob *me);
113
114   /* offsets */
115   void translate_axis (Real, Axis);
116   Real relative_coordinate (Grob const *refp, Axis) const;
117   Real pure_relative_y_coordinate (Grob const *refp, int start, int end);
118   Real maybe_pure_coordinate (Grob const *refp, Axis a, bool pure, int start, int end);
119
120   /* extents */
121   Interval extent (Grob *refpoint, Axis) const;
122   void flush_extent_cache (Axis);
123   Interval pure_height (Grob *refpoint, int start_col, int end_col);
124   Interval maybe_pure_extent (Grob *refpoint, Axis, bool pure, int start, int end);
125
126   /* refpoints */
127   Grob *common_refpoint (Grob const *s, Axis a) const;
128   void set_parent (Grob *e, Axis);
129   Grob *get_parent (Axis a) const;
130   void fixup_refpoint ();
131
132   virtual Interval_t<int> spanned_rank_iv ();
133 };
134
135 /* smob utilities */
136 DECLARE_UNSMOB (Grob, grob);
137 Spanner *unsmob_spanner (SCM);
138 Item *unsmob_item (SCM);
139
140 /* refpoints */
141 Grob *common_refpoint_of_list (SCM elt_list, Grob *, Axis a);
142 Grob *common_refpoint_of_array (vector<Grob*> const &, Grob *, Axis a);
143 System *get_root_system (Grob *me);
144
145 /* extents */ 
146 Interval robust_relative_extent (Grob *, Grob *, Axis);
147
148 /* offset/extent callbacks. */
149 void add_offset_callback (Grob *g, SCM proc, Axis a);
150 void chain_offset_callback (Grob *g, SCM proc, Axis a);
151 SCM axis_offset_symbol (Axis a);
152 SCM axis_parent_positioning (Axis a);
153
154 #endif /* GROB_HH */