]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/grob.cc
* lily/grob.cc (get_stencil): simplify: use callback mechanism to
[lilypond.git] / lily / grob.cc
index 3a019cea6ec54f251e7063db9602bfe8328d175f..b85e61824d12a5ece5211269e2e000a6e54e8f4e 100644 (file)
 #include "ly-smobs.icc"
 #include "output-def.hh"
 
+MAKE_SCHEME_CALLBACK(Grob, same_axis_parent_positioning, 2);
+SCM
+Grob::same_axis_parent_positioning (SCM element_smob, SCM axis)
+{
+  Grob *me = unsmob_grob (element_smob);
+  Axis ax = Axis (scm_to_int (axis));
+  
+  Grob *par = me->get_parent (ax);
+  if (par)
+    par->get_property ("positioning-done");
+
+  return scm_from_double (0.0);
+}
+
+MAKE_SCHEME_CALLBACK(Grob,other_axis_parent_positioning, 2);
+SCM
+Grob::other_axis_parent_positioning (SCM element_smob, SCM axis)
+{
+  Grob *me = unsmob_grob (element_smob);
+  Axis ax = other_axis ((Axis) scm_to_int (axis));
+  
+  Grob *par = me->get_parent (ax);
+  if (par)
+    par->get_property ("positioning-done");
+
+  return scm_from_double (0.0);
+}
+
+
+
 Grob *
 Grob::clone (int count) const
 {
@@ -55,7 +85,8 @@ Grob::Grob (SCM basicprops,
   immutable_property_alist_ = basicprops;
   mutable_property_alist_ = SCM_EOL;
   object_alist_ = SCM_EOL;
-
+  property_callbacks_ = SCM_EOL;
+  
   /* We do smobify_self () as the first step.  Since the object lives
      on the heap, none of its SCM variables are protected from
      GC. After smobify_self (), they are.  */
@@ -78,6 +109,8 @@ Grob::Grob (SCM basicprops,
   creation. Convenient eg. when using \override with
   StaffSymbol.  */
 
+  property_callbacks_ = get_property ("callbacks");
+
   SCM off_callbacks[] = {
     get_property ("X-offset-callbacks"),
     get_property ("Y-offset-callbacks")
@@ -113,9 +146,11 @@ Grob::Grob (SCM basicprops,
       else if (ly_is_procedure (cb))
        dim_cache_[a].dimension_callback_ = cb;
       else if (cb == SCM_EOL
-              && ly_is_procedure (get_property ("print-function")))
+              && ly_is_procedure (ly_assoc_get (ly_symbol2scm ("stencil"),
+                                                property_callbacks_, SCM_BOOL_F)))
        dim_cache_[a].dimension_callback_ = stencil_extent_proc;
     }
+
 }
 
 Grob::Grob (Grob const &s, int copy_index)
@@ -128,11 +163,9 @@ Grob::Grob (Grob const &s, int copy_index)
   immutable_property_alist_ = s.immutable_property_alist_;
   mutable_property_alist_ = ly_deep_copy (s.mutable_property_alist_);
   interfaces_ = s.interfaces_;
+  property_callbacks_ = s.property_callbacks_;
   object_alist_ = SCM_EOL;
 
-  /* No properties are copied.  That is the job of
-     handle_broken_dependencies.  */
-  status_ = s.status_;
   pscore_ = 0;
 
   smobify_self ();
@@ -174,36 +207,6 @@ Grob::get_layout () const
   return pscore_ ? pscore_->layout () : 0;
 }
 
-/* Recursively track all dependencies of this Grob.  The status_ field
-   is used as a mark-field.  It is marked with BUSY during execution
-   of this function, and marked with FINAL when finished.
-
-   FUNCPTR is the function to call to update this element.  */
-void
-Grob::calculate_dependencies (int final, int busy, SCM funcname)
-{
-  if (status_ >= final)
-    return;
-
-  if (status_ == busy)
-    {
-      programming_error ("element is busy, come back later");
-      return;
-    }
-
-  status_ = busy;
-
-  extract_grob_set (this, "dependencies", deps);
-  for (int i = 0; i < deps.size (); i++)
-    deps[i]->calculate_dependencies (final, busy, funcname);
-
-  SCM proc = internal_get_property (funcname);
-  if (ly_is_procedure (proc))
-    scm_call_1 (proc, this->self_scm ());
-
-  status_ = final;
-}
-
 Stencil *
 Grob::get_stencil () const
 {
@@ -211,39 +214,27 @@ Grob::get_stencil () const
     return 0;
 
   SCM stil = get_property ("stencil");
-  if (unsmob_stencil (stil))
-    return unsmob_stencil (stil);
-
-  stil = get_uncached_stencil ();
-  if (is_live ())
-    {
-      Grob *me = (Grob *) this;
-      me->set_property ("stencil", stil);
-    }
-
   return unsmob_stencil (stil);
 }
 
-SCM
-Grob::get_uncached_stencil () const
+Stencil
+Grob::get_print_stencil () const
 {
-  SCM proc = get_property ("print-function");
-
-  SCM stil = SCM_EOL;
-  if (ly_is_procedure (proc))
-    stil = scm_apply_0 (proc, scm_list_n (this->self_scm (), SCM_UNDEFINED));
+  SCM stil = get_property ("stencil");
 
+  Stencil retval;
   if (Stencil *m = unsmob_stencil (stil))
     {
+      retval = *m;
       if (to_boolean (get_property ("transparent")))
-       stil = Stencil (m->extent_box (), SCM_EOL).smobbed_copy ();
+       retval = Stencil (m->extent_box (), SCM_EOL);
       else
        {
          SCM expr = m->expr ();
          if (point_and_click_global)
            expr = scm_list_3 (ly_symbol2scm ("grob-cause"), self_scm (), expr);
 
-         stil = Stencil (m->extent_box (), expr).smobbed_copy ();
+         retval = Stencil (m->extent_box (), expr);
        }
 
       /* color support... see interpret_stencil_expression () for more... */
@@ -255,11 +246,12 @@ Grob::get_uncached_stencil () const
                                 color,
                                 m->expr ());
 
-         stil = Stencil (m->extent_box (), expr).smobbed_copy ();
+         retval = Stencil (m->extent_box (), expr);
        }
+
     }
 
-  return stil;
+  return retval;
 }
 
 /*
@@ -276,14 +268,6 @@ Grob::get_system () const
   return 0;
 }
 
-void
-Grob::add_dependency (Grob *e)
-{
-  if (e)
-    Pointer_group_interface::add_grob (this, ly_symbol2scm ("dependencies"), e);
-  else
-    programming_error ("null dependency added");
-}
 
 void
 Grob::handle_broken_dependencies ()
@@ -331,6 +315,7 @@ Grob::suicide ()
 
   mutable_property_alist_ = SCM_EOL;
   object_alist_ = SCM_EOL;
+  property_callbacks_ = SCM_EOL;
   immutable_property_alist_ = SCM_EOL;
   interfaces_ = SCM_EOL;
 
@@ -534,7 +519,7 @@ Grob::name () const
   SCM meta = get_property ("meta");
   SCM nm = scm_assoc (ly_symbol2scm ("name"), meta);
   nm = (scm_is_pair (nm)) ? scm_cdr (nm) : SCM_EOL;
-  return scm_is_symbol (nm) ? ly_symbol2string (nm) : classname (this);
+  return scm_is_symbol (nm) ? ly_symbol2string (nm) : this->class_name ();
 }
 
 void
@@ -717,14 +702,41 @@ ADD_INTERFACE (Grob, "grob-interface",
               "Mutable properties are variables that are specific to one grob. Typically, "
               "lists of other objects, or results from computations are stored in"
               "mutable properties: every call to set-grob-property (or its C++ equivalent) "
-              "sets a mutable property. ",
-              "X-offset-callbacks Y-offset-callbacks X-extent-callback stencil cause "
-              "Y-extent-callback print-function extra-offset spacing-procedure "
-              "context staff-symbol interfaces dependencies X-extent Y-extent extra-X-extent "
-              "meta layer before-line-breaking-callback "
-              "color "
+              "sets a mutable property. "
+              "\n\n"
+              "The properties @code{after-line-breaking} and @code{before-line-breaking} "
+              "are dummies that are not user-serviceable. "
+
+              ,
+
+              /* properties */
+              "X-extent "
+              "X-extent-callback "
+              "X-offset-callbacks "
+              "Y-extent "
+              "Y-extent-callback "
+              "Y-offset-callbacks "
+              "after-line-breaking "
               "axis-group-parent-X "
               "axis-group-parent-Y "
-              "after-line-breaking-callback extra-Y-extent minimum-X-extent "
-              "minimum-Y-extent transparent");
+              "before-line-breaking "
+              "callbacks "
+              "cause "
+              "color "
+              "context "
+              "extra-X-extent "
+              "extra-Y-extent "
+              "extra-offset "
+              "interfaces "
+              "layer "
+              "meta "
+              "minimum-X-extent "
+              "minimum-Y-extent "
+              "print-function "
+              "spacing-procedure "
+              "staff-symbol "
+              "stencil "
+              "transparent"
+              );
+