]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/grob.hh
f5c6ac96e5467d338bfc6c393d12539c30791dbf
[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 : public Smob<Grob>
31 {
32 public:
33   int print_smob (SCM, scm_print_state *);
34   SCM mark_smob ();
35   static const char type_p_name_[];
36   virtual ~Grob ();
37 private:
38   DECLARE_CLASSNAME (Grob);
39
40   void init ();
41
42 protected:
43   /* data */
44   Dimension_cache dim_cache_[NO_AXES];
45   Output_def *layout_;
46   Grob *original_;
47
48   /* SCM data */
49   SCM immutable_property_alist_;
50   SCM mutable_property_alist_;
51   SCM object_alist_;
52
53   /*
54     If this is a property, it accounts for 25% of the property
55     lookups.
56   */
57   SCM interfaces_;
58
59   void substitute_object_links (SCM, SCM);
60   Real get_offset (Axis a) const;
61   SCM try_callback (SCM, SCM);
62   SCM try_callback_on_alist (SCM *, SCM, SCM);
63   void internal_set_value_on_alist (SCM *alist, SCM sym, SCM val);
64
65 public:
66
67   /* friends */
68   friend class Spanner;
69   friend class System;
70   friend SCM ly_grob_properties (SCM);
71   friend SCM ly_grob_basic_properties (SCM);
72
73   /* standard callbacks */
74   DECLARE_SCHEME_CALLBACK (x_parent_positioning, (SCM));
75   DECLARE_SCHEME_CALLBACK (y_parent_positioning, (SCM));
76   DECLARE_SCHEME_CALLBACK (pure_stencil_height, (SCM smob, SCM, SCM));
77   DECLARE_SCHEME_CALLBACK (stencil_height, (SCM smob));
78   DECLARE_SCHEME_CALLBACK (stencil_width, (SCM smob));
79   DECLARE_SCHEME_CALLBACK (pure_simple_vertical_skylines_from_extents, (SCM smob, SCM, SCM));
80   DECLARE_SCHEME_CALLBACK (simple_vertical_skylines_from_extents, (SCM smob));
81   DECLARE_SCHEME_CALLBACK (vertical_skylines_from_stencil, (SCM smob));
82   DECLARE_SCHEME_CALLBACK (pure_vertical_skylines_from_element_stencils, (SCM smob, SCM, SCM));
83   DECLARE_SCHEME_CALLBACK (vertical_skylines_from_element_stencils, (SCM smob));
84   DECLARE_SCHEME_CALLBACK (pure_simple_horizontal_skylines_from_extents, (SCM smob, SCM, SCM));
85   DECLARE_SCHEME_CALLBACK (simple_horizontal_skylines_from_extents, (SCM smob));
86   DECLARE_SCHEME_CALLBACK (horizontal_skylines_from_stencil, (SCM smob));
87   DECLARE_SCHEME_CALLBACK (pure_horizontal_skylines_from_element_stencils, (SCM smob, SCM, SCM));
88   DECLARE_SCHEME_CALLBACK (horizontal_skylines_from_element_stencils, (SCM smob));
89
90   /* R/O access */
91   Output_def *layout () const { return layout_; }
92   Grob *original () const { return original_; }
93   SCM interfaces () const { return interfaces_; }
94
95   /* life & death */
96   Grob (SCM basic_props);
97   Grob (Grob const &);
98   virtual Grob *clone () const;
99
100   /* forced death */
101   void suicide ();
102   bool is_live () const;
103
104   /* naming. */
105   string name () const;
106
107   /* Properties */
108   SCM get_property_alist_chain (SCM) const;
109   SCM internal_get_property (SCM symbol) const;
110   SCM internal_get_property_data (SCM symbol) const;
111   SCM internal_get_pure_property (SCM symbol, int start, int end) const;
112   SCM internal_get_maybe_pure_property (SCM symbol, bool pure, int start, int end) const;
113   SCM internal_get_non_callback_marker_property_data (SCM symbol) const;
114   SCM internal_get_object (SCM symbol) const;
115   void internal_set_object (SCM sym, SCM val);
116   void internal_del_property (SCM symbol);
117   void instrumented_set_property (SCM, SCM, char const *, int, char const *);
118   void internal_set_property (SCM sym, SCM val);
119
120   /* messages */
121   void warning (const string&) const;
122   void programming_error (const string&) const;
123
124   /* class hierarchy */
125   virtual System *get_system () const;
126   static System *get_system (Grob *);
127   virtual void do_break_processing ();
128   virtual Grob *find_broken_piece (System *) const;
129   virtual void discretionary_processing ();
130   virtual void derived_mark () const;
131   virtual void handle_broken_dependencies ();
132   virtual void handle_prebroken_dependencies ();
133
134   /* printing */
135   Stencil *get_stencil () const;
136   Stencil get_print_stencil () const;
137
138   /* interfaces */
139   bool internal_has_interface (SCM intf);
140   DECLARE_GROB_INTERFACE ();
141
142   /* offsets */
143   void translate_axis (Real, Axis);
144   Real relative_coordinate (Grob const *refp, Axis) const;
145   Real pure_relative_y_coordinate (Grob const *refp, int start, int end);
146   Real maybe_pure_coordinate (Grob const *refp, Axis a, bool pure, int start, int end);
147
148   /* extents */
149   Interval extent (Grob *refpoint, Axis) const;
150   void flush_extent_cache (Axis);
151   virtual Interval pure_height (Grob *refpoint, int start_col, int end_col);
152   Interval maybe_pure_extent (Grob *refpoint, Axis, bool pure, int start, int end);
153
154   /* refpoints */
155   Grob *common_refpoint (Grob const *s, Axis a) const;
156   void set_parent (Grob *e, Axis);
157   Grob *get_parent (Axis a) const;
158   void fixup_refpoint ();
159
160   /* vertical ordering */
161   static bool internal_vertical_less (Grob *g1, Grob *g2, bool pure);
162   static Grob *get_root_vertical_alignment (Grob *g);
163   static Grob *get_vertical_axis_group (Grob *g);
164   static bool vertical_less (Grob *g1, Grob *g2);
165   static bool pure_vertical_less (Grob *g1, Grob *g2);
166   static int get_vertical_axis_group_index (Grob *g);
167
168   /* skylines */
169   virtual Interval_t<int> spanned_rank_interval () const;
170   virtual bool pure_is_visible (int start, int end) const;
171   bool check_cross_staff (Grob *common);
172   static bool less (Grob *g1, Grob *g2);
173   static SCM maybe_pure_internal_simple_skylines_from_extents (Grob *, Axis, bool, int, int, bool, bool);
174   static SCM internal_skylines_from_element_stencils (Grob *me, Axis a, bool pure, int beg, int end);
175   static SCM internal_skylines_from_element_stencils (SCM, Axis);
176 };
177
178 /* unification */
179 void uniquify (vector <Grob *> &);
180
181 /* refpoints */
182 Grob *common_refpoint_of_list (SCM elt_list, Grob *, Axis a);
183 Grob *common_refpoint_of_array (vector<Grob *> const &, Grob *, Axis a);
184 Grob *common_refpoint_of_array (set<Grob *> const &, Grob *, Axis a);
185 System *get_root_system (Grob *me);
186
187 /* extents */
188 Interval robust_relative_extent (Grob *, Grob *, Axis);
189
190 /* offset/extent callbacks. */
191 void add_offset_callback (Grob *g, SCM proc, Axis a);
192 void chain_offset_callback (Grob *g, SCM proc, Axis a);
193 void chain_callback (Grob *g, SCM proc, SCM sym);
194 SCM axis_offset_symbol (Axis a);
195 SCM axis_parent_positioning (Axis a);
196
197 SCM call_pure_function (SCM unpure, SCM args, int start, int end);
198
199 void set_nested_property (Grob *, SCM property_path, SCM value);
200
201 #endif /* GROB_HH */