]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/grob.hh
83ec5f73edf25cfa79ca5316290745bd4437f37f
[lilypond.git] / lily / include / grob.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1996--2014 Han-Wen Nienhuys
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef GROB_HH
21 #define GROB_HH
22
23 #include "box.hh"
24 #include "virtual-methods.hh"
25 #include "dimension-cache.hh"
26 #include "grob-interface.hh"
27
28 #include <set>
29
30 class Grob
31 {
32 private:
33   DECLARE_SMOBS (Grob);
34   DECLARE_CLASSNAME (Grob);
35
36   void init ();
37
38 protected:
39   /* data */
40   Dimension_cache dim_cache_[NO_AXES];
41   Output_def *layout_;
42   Grob *original_;
43
44   /* SCM data */
45   SCM immutable_property_alist_;
46   SCM mutable_property_alist_;
47   SCM object_alist_;
48
49   /*
50     If this is a property, it accounts for 25% of the property
51     lookups.
52   */
53   SCM interfaces_;
54
55   void substitute_object_links (SCM, SCM);
56   Real get_offset (Axis a) const;
57   SCM try_callback (SCM, SCM);
58   SCM try_callback_on_alist (SCM *, SCM, SCM);
59   void internal_set_value_on_alist (SCM *alist, SCM sym, SCM val);
60
61 public:
62
63   /* friends */
64   friend class Spanner;
65   friend class System;
66   friend SCM ly_grob_properties (SCM);
67   friend SCM ly_grob_basic_properties (SCM);
68
69   /* standard callbacks */
70   DECLARE_SCHEME_CALLBACK (x_parent_positioning, (SCM));
71   DECLARE_SCHEME_CALLBACK (y_parent_positioning, (SCM));
72   DECLARE_SCHEME_CALLBACK (pure_stencil_height, (SCM smob, SCM, SCM));
73   DECLARE_SCHEME_CALLBACK (stencil_height, (SCM smob));
74   DECLARE_SCHEME_CALLBACK (stencil_width, (SCM smob));
75   DECLARE_SCHEME_CALLBACK (pure_simple_vertical_skylines_from_extents, (SCM smob, SCM, SCM));
76   DECLARE_SCHEME_CALLBACK (simple_vertical_skylines_from_extents, (SCM smob));
77   DECLARE_SCHEME_CALLBACK (vertical_skylines_from_stencil, (SCM smob));
78   DECLARE_SCHEME_CALLBACK (pure_vertical_skylines_from_element_stencils, (SCM smob, SCM, SCM));
79   DECLARE_SCHEME_CALLBACK (vertical_skylines_from_element_stencils, (SCM smob));
80   DECLARE_SCHEME_CALLBACK (pure_simple_horizontal_skylines_from_extents, (SCM smob, SCM, SCM));
81   DECLARE_SCHEME_CALLBACK (simple_horizontal_skylines_from_extents, (SCM smob));
82   DECLARE_SCHEME_CALLBACK (horizontal_skylines_from_stencil, (SCM smob));
83   DECLARE_SCHEME_CALLBACK (pure_horizontal_skylines_from_element_stencils, (SCM smob, SCM, SCM));
84   DECLARE_SCHEME_CALLBACK (horizontal_skylines_from_element_stencils, (SCM smob));
85
86   /* R/O access */
87   Output_def *layout () const { return layout_; }
88   Grob *original () const { return original_; }
89   SCM interfaces () const { return interfaces_; }
90
91   /* life & death */
92   Grob (SCM basic_props);
93   Grob (Grob const &);
94   virtual Grob *clone () const;
95
96   /* forced death */
97   void suicide ();
98   bool is_live () const;
99
100   /* naming. */
101   string name () const;
102
103   /* Properties */
104   SCM get_property_alist_chain (SCM) const;
105   SCM internal_get_property (SCM symbol) const;
106   SCM internal_get_property_data (SCM symbol) const;
107   SCM internal_get_pure_property (SCM symbol, int start, int end) const;
108   SCM internal_get_maybe_pure_property (SCM symbol, bool pure, int start, int end) const;
109   SCM internal_get_non_callback_marker_property_data (SCM symbol) const;
110   SCM internal_get_object (SCM symbol) const;
111   void internal_set_object (SCM sym, SCM val);
112   void internal_del_property (SCM symbol);
113   void instrumented_set_property (SCM, SCM, char const *, int, char const *);
114   void internal_set_property (SCM sym, SCM val);
115
116   /* messages */
117   void warning (const string&) const;
118   void programming_error (const string&) const;
119
120   /* class hierarchy */
121   virtual System *get_system () const;
122   static System *get_system (Grob *);
123   virtual void do_break_processing ();
124   virtual Grob *find_broken_piece (System *) const;
125   virtual void discretionary_processing ();
126   virtual void derived_mark () const;
127   virtual void handle_broken_dependencies ();
128   virtual void handle_prebroken_dependencies ();
129
130   /* printing */
131   Stencil *get_stencil () const;
132   Stencil get_print_stencil () const;
133
134   /* interfaces */
135   bool internal_has_interface (SCM intf);
136   DECLARE_GROB_INTERFACE ();
137
138   /* offsets */
139   void translate_axis (Real, Axis);
140   Real relative_coordinate (Grob const *refp, Axis) const;
141   Real pure_relative_y_coordinate (Grob const *refp, int start, int end);
142   Real maybe_pure_coordinate (Grob const *refp, Axis a, bool pure, int start, int end);
143
144   /* extents */
145   Interval extent (Grob *refpoint, Axis) const;
146   void flush_extent_cache (Axis);
147   virtual Interval pure_height (Grob *refpoint, int start_col, int end_col);
148   Interval maybe_pure_extent (Grob *refpoint, Axis, bool pure, int start, int end);
149
150   /* refpoints */
151   Grob *common_refpoint (Grob const *s, Axis a) const;
152   void set_parent (Grob *e, Axis);
153   Grob *get_parent (Axis a) const;
154   void fixup_refpoint ();
155
156   /* vertical ordering */
157   static bool internal_vertical_less (Grob *g1, Grob *g2, bool pure);
158   static Grob *get_root_vertical_alignment (Grob *g);
159   static Grob *get_vertical_axis_group (Grob *g);
160   static bool vertical_less (Grob *g1, Grob *g2);
161   static bool pure_vertical_less (Grob *g1, Grob *g2);
162   static int get_vertical_axis_group_index (Grob *g);
163
164   /* skylines */
165   virtual Interval_t<int> spanned_rank_interval () const;
166   virtual bool pure_is_visible (int start, int end) const;
167   bool check_cross_staff (Grob *common);
168   static bool less (Grob *g1, Grob *g2);
169   static SCM maybe_pure_internal_simple_skylines_from_extents (Grob *, Axis, bool, int, int, bool, bool);
170   static SCM internal_skylines_from_element_stencils (Grob *me, Axis a, bool pure, int beg, int end);
171   static SCM internal_skylines_from_element_stencils (SCM, Axis);
172 };
173
174 /* smob utilities */
175 DECLARE_UNSMOB (Grob, grob);
176 Spanner *unsmob_spanner (SCM);
177 Item *unsmob_item (SCM);
178
179 /* unification */
180 void uniquify (vector <Grob *> &);
181
182 /* refpoints */
183 Grob *common_refpoint_of_list (SCM elt_list, Grob *, Axis a);
184 Grob *common_refpoint_of_array (vector<Grob *> const &, Grob *, Axis a);
185 Grob *common_refpoint_of_array (set<Grob *> const &, Grob *, Axis a);
186 System *get_root_system (Grob *me);
187
188 /* extents */
189 Interval robust_relative_extent (Grob *, Grob *, Axis);
190
191 /* offset/extent callbacks. */
192 void add_offset_callback (Grob *g, SCM proc, Axis a);
193 void chain_offset_callback (Grob *g, SCM proc, Axis a);
194 void chain_callback (Grob *g, SCM proc, SCM sym);
195 SCM axis_offset_symbol (Axis a);
196 SCM axis_parent_positioning (Axis a);
197
198 SCM call_pure_function (SCM unpure, SCM args, int start, int end);
199
200 void set_nested_property (Grob *, SCM property_path, SCM value);
201
202 #endif /* GROB_HH */