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