]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/hara-kiri-group-spanner.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / hara-kiri-group-spanner.cc
index 0094a018ed9083f2c223d96921d04ccd03bb39c4..f8420239eef6eb7d9c59565b3cecee3d82547956 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
-  Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
+  Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
-#include "axis-group-interface.hh"
 #include "hara-kiri-group-spanner.hh"
-#include "debug.hh"
-#include "item.hh"
 
-/*
- */
-Hara_kiri_group_spanner::Hara_kiri_group_spanner(SCM s)
-  : Spanner (s)
-{
-  set_elt_pointer ("items-worth-living", SCM_EOL);
-}
+#include "paper-column.hh"
+#include "pointer-group-interface.hh"
+#include "axis-group-interface.hh"
+#include "spanner.hh"
+#include "warn.hh"
+#include "item.hh"
 
-void 
-Hara_kiri_group_spanner::add_interesting_item (Item* n)
+MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, y_extent, 1);
+SCM
+Hara_kiri_group_spanner::y_extent (SCM smob)
 {
-  add_dependency (n);
-  Pointer_group_interface (this, "items-worth-living").add_element (n);
-
+  Grob *me = unsmob_grob (smob);
+  consider_suicide (me);
+  return Axis_group_interface::generic_group_extent (me, Y_AXIS);
 }
 
-GLUE_SCORE_ELEMENT(Hara_kiri_group_spanner,after_line_breaking);
-SCM 
-Hara_kiri_group_spanner::member_after_line_breaking ()
+void
+Hara_kiri_group_spanner::consider_suicide (Grob *me)
 {
-  SCM worth = get_elt_pointer ("items-worth-living");
-  /*
-    worth == self_scm  is a stupid way to signal that we're done.
-   */
-  if (gh_pair_p (worth))
-    return SCM_UNDEFINED;
-
-  Link_array<Score_element> childs = Axis_group_interface (this).get_children ();
+  Spanner *sp = dynamic_cast<Spanner *> (me);
+  if (!to_boolean (me->get_property ("remove-empty")))
+    return ;
+
+  extract_grob_set (me, "items-worth-living", worth);
+  if (worth.size ())
+    return;
+
+  bool remove_first = to_boolean (me->get_property ("remove-first"));
+  if (!remove_first
+       && ((sp->original () && broken_spanner_index (sp) == 0)
+          || Paper_column::get_rank (sp->get_bound (LEFT)->get_column ())
+          == 0)) 
+    return;
+
+  Link_array<Grob> childs;
+  Axis_group_interface::get_children (me, &childs);
   for (int i = 0; i < childs.size (); i++)
-    {
-      Score_element* s = childs[i];
-
-      if ( line_l () != s->line_l ())
-       programming_error ("Killing other children too");
-      s->suicide ();
-    }
+    childs[i]->suicide ();
 
   /*
     very appropriate name here :-)
-   */
-  suicide ();
-  return SCM_UNDEFINED;
+  */
+  me->suicide ();
 }
 
-
-
 /*
   We can't rely on offsets and dimensions of elements in a hara-kiri
   group. Use a callback to make sure that hara-kiri has been done
   before asking for offsets.  */
-Real
-Hara_kiri_group_spanner::force_hara_kiri_callback (Score_element const  *elt, Axis a)
+MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_callback, 2);
+SCM
+Hara_kiri_group_spanner::force_hara_kiri_callback (SCM smob, SCM axis)
 {
-  while (elt && !dynamic_cast<Hara_kiri_group_spanner const*> (elt))
-    elt = elt->parent_l(a);
+  Grob *me = unsmob_grob (smob);
+  (void) axis;
 
-  if (elt)
-    {
-      Hara_kiri_group_spanner const  * seppuku = dynamic_cast<Hara_kiri_group_spanner const*> (elt);
+  assert (scm_to_int (axis) == Y_AXIS);
+  consider_suicide (me);
+  return scm_from_double (0.0);
+}
 
-      ((Hara_kiri_group_spanner*)seppuku)->member_after_line_breaking ();
-    }
-  
+MAKE_SCHEME_CALLBACK (Hara_kiri_group_spanner, force_hara_kiri_in_parent_callback, 2);
+SCM
+Hara_kiri_group_spanner::force_hara_kiri_in_parent_callback (SCM smob, SCM axis)
+{
+  Grob *daughter = unsmob_grob (smob);
+  Axis a = (Axis) scm_to_int (axis);
+  assert (a == Y_AXIS);
+  force_hara_kiri_callback (daughter->get_parent (a)->self_scm (), axis);
+  return scm_from_double (0.0);
+}
 
-  return 0.0;
+void
+Hara_kiri_group_spanner::add_interesting_item (Grob *me, Grob *n)
+{
+  Pointer_group_interface::add_grob (me, ly_symbol2scm ("items-worth-living"), n);
 }
+
+ADD_INTERFACE (Hara_kiri_group_spanner, "hara-kiri-group-interface",
+              "A group spanner that  keeps track of interesting items.  If it "
+              "doesn't contain any after linebreaking, then it "
+              "will remove itself and all its children.",
+
+
+              /* properties */
+              "items-worth-living "
+              "remove-empty "
+              "remove-first "
+              );
+
+