]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/context-property.cc
Documentation/user/programming-interface.itely: fix @{ @}.
[lilypond.git] / lily / context-property.cc
index 940643e7660d8d04f80a4893afcf275acfd51f4e..959d6309f65107a46e59acd4493fab455e2e1071 100644 (file)
@@ -13,6 +13,7 @@
 #include "main.hh"
 #include "spanner.hh"
 #include "warn.hh"
+#include "paper-column.hh"
 
 /*
   Grob descriptions (ie. alists with layout properties) are
@@ -30,12 +31,12 @@ void
 execute_pushpop_property (Context *trg,
                          SCM prop, SCM eltprop, SCM val)
 {
+  SCM prev = SCM_EOL;
   if (scm_is_symbol (prop) && scm_is_symbol (eltprop))
     {
       if (val != SCM_UNDEFINED)
        {
-         SCM prev = SCM_EOL;
-         Context *where = trg->where_defined (prop);
+         Context *where = trg->where_defined (prop, &prev);
 
          /*
            Don't mess with MIDI.
@@ -49,8 +50,6 @@ execute_pushpop_property (Context *trg,
              prev = scm_cons (base, base);
              trg->internal_set_property (prop, prev);
            }
-         else
-           prev = trg->internal_get_property (prop);
 
          if (!scm_is_pair (prev))
            {
@@ -75,9 +74,8 @@ execute_pushpop_property (Context *trg,
              // warning here.
            }
        }
-      else if (trg->where_defined (prop) == trg)
+      else if (trg->where_defined (prop, &prev) == trg)
        {
-         SCM prev = trg->internal_get_property (prop);
          SCM prev_alist = scm_car (prev);
          SCM daddy = scm_cdr (prev);
 
@@ -86,7 +84,7 @@ execute_pushpop_property (Context *trg,
 
          while (prev_alist != daddy)
            {
-             if (ly_c_equal_p (scm_caar (prev_alist), eltprop))
+             if (ly_is_equal (scm_caar (prev_alist), eltprop))
                {
                  prev_alist = scm_cdr (prev_alist);
                  break;
@@ -150,7 +148,8 @@ updated_grob_properties (Context *tg, SCM sym)
 {
   assert (scm_is_symbol (sym));
 
-  tg = tg->where_defined (sym);
+  SCM props;
+  tg = tg->where_defined (sym, &props);
   if (!tg)
     return SCM_EOL;
 
@@ -159,8 +158,6 @@ updated_grob_properties (Context *tg, SCM sym)
     ? updated_grob_properties (tg->get_parent_context (), sym)
     : SCM_EOL;
 
-  SCM props = tg->internal_get_property (sym);
-
   if (!scm_is_pair (props))
     {
       programming_error ("grob props not a pair?");
@@ -191,30 +188,51 @@ updated_grob_properties (Context *tg, SCM sym)
     }
 }
 
-Item *
-make_item_from_properties (Engraver *tr, SCM x, SCM cause, const char *name)
+Grob *
+make_grob_from_properties (Engraver *tr, SCM symbol, SCM cause, const char *name)
 {
   Context *context = tr->context ();
 
-  SCM props = updated_grob_properties (context, x);
+  SCM props = updated_grob_properties (context, symbol);
 
   Object_key const *key = context->get_grob_key (name);
-  Item *it = new Item (props, key);
-
-  dynamic_cast<Engraver *> (tr)->announce_grob (it, cause);
+  Grob *grob = 0;
+  
+  SCM handle = scm_sloppy_assq (ly_symbol2scm ("meta"), props);
+  SCM klass = scm_cdr (scm_sloppy_assq (ly_symbol2scm ("class"), scm_cdr (handle)));
+  
+  if (klass == ly_symbol2scm ("Item"))
+    grob = new Item (props, key);
+  else if (klass == ly_symbol2scm ("Spanner"))
+    grob = new Spanner (props, key);
+  else if (klass == ly_symbol2scm ("Paper_column"))
+    grob = new Paper_column (props, key);
+
+  assert (grob);
+  dynamic_cast<Engraver *> (tr)->announce_grob (grob, cause);
+
+  return grob;
+}
 
+Item *
+make_item_from_properties (Engraver *tr, SCM x, SCM cause, const char *name)
+{
+  Item *it = dynamic_cast<Item*> (make_grob_from_properties (tr, x, cause, name));
+  assert (it);
   return it;
 }
 
-Spanner *
-make_spanner_from_properties (Engraver *tr, SCM x, SCM cause, const char *name)
+Paper_column *
+make_paper_column_from_properties (Engraver *tr, SCM x, const char *name)
 {
-  Context *context = tr->context ();
-
-  SCM props = updated_grob_properties (context, x);
-  Spanner *it = new Spanner (props, context->get_grob_key (name));
+  return dynamic_cast<Paper_column*> (make_grob_from_properties (tr, x, SCM_EOL, name));
+}
 
-  dynamic_cast<Engraver *> (tr)->announce_grob (it, cause);
 
-  return it;
+Spanner *
+make_spanner_from_properties (Engraver *tr, SCM x, SCM cause, const char *name)
+{
+  Spanner* sp = dynamic_cast<Spanner*> (make_grob_from_properties (tr, x, cause, name));
+  assert (sp);
+  return sp;
 }