X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fgrob-scheme.cc;h=f10ee2106fe762f73569e03794d1ba26358b8d8d;hb=54b02666750062788185bd3f99e644d621e348c2;hp=6e18c54278c615028cf344948a306675d96a1721;hpb=b7a0cffbf9d1069860368f289a5b50e9d1d90ba8;p=lilypond.git diff --git a/lily/grob-scheme.cc b/lily/grob-scheme.cc index 6e18c54278..f10ee2106f 100644 --- a/lily/grob-scheme.cc +++ b/lily/grob-scheme.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1998--2009 Jan Nieuwenhuizen + Copyright (C) 1998--2011 Jan Nieuwenhuizen Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify @@ -18,13 +18,14 @@ along with LilyPond. If not, see . */ -#include "warn.hh" // error () +#include "font-interface.hh" +#include "grob-array.hh" #include "item.hh" #include "output-def.hh" -#include "system.hh" -#include "font-interface.hh" #include "paper-score.hh" -#include "grob-array.hh" +#include "simple-closure.hh" +#include "system.hh" +#include "warn.hh" // error () LY_DEFINE (ly_grob_property_data, "ly:grob-property-data", 2, 0, 0, (SCM grob, SCM sym), @@ -49,6 +50,7 @@ LY_DEFINE (ly_grob_set_property_x, "ly:grob-set-property!", LY_ASSERT_TYPE (ly_is_symbol, sym, 2); if (!ly_is_procedure (val) + && !is_simple_closure (val) && !type_check_assignment (sym, val, ly_symbol2scm ("backend-type?"))) error ("typecheck failed"); @@ -56,6 +58,27 @@ LY_DEFINE (ly_grob_set_property_x, "ly:grob-set-property!", return SCM_UNSPECIFIED; } +LY_DEFINE (ly_grob_set_nested_property_x, "ly:grob-set-nested-property!", + 3, 0, 0, (SCM grob, SCM symlist, SCM val), + "Set nested property @var{symlist} in grob @var{grob} to value @var{val}.") +{ + Grob *sc = unsmob_grob (grob); + + LY_ASSERT_SMOB (Grob, grob, 1); + + bool type_ok = ly_cheap_is_list (symlist); + + if (type_ok) + for (SCM s = symlist; scm_is_pair (s) && type_ok; s = scm_cdr (s)) + type_ok &= ly_is_symbol (scm_car (s)); + + SCM_ASSERT_TYPE (type_ok, symlist, SCM_ARG2, __FUNCTION__, "list of symbols"); + + set_nested_property (sc, symlist, val); + return SCM_UNSPECIFIED; +} + + LY_DEFINE (ly_grob_property, "ly:grob-property", 2, 1, 0, (SCM grob, SCM sym, SCM val), "Return the value for property @var{sym} of @var{grob}." @@ -90,9 +113,9 @@ LY_DEFINE (ly_grob_interfaces, "ly:grob-interfaces", LY_DEFINE (ly_grob_object, "ly:grob-object", 2, 0, 0, (SCM grob, SCM sym), - "Return the value of a pointer in grob@tie{}@var{g} of property" + "Return the value of a pointer in grob @var{grob} of property" " @var{sym}. It returns @code{'()} (end-of-list) if @var{sym}" - " is undefined in@tie{}@var{g}.") + " is undefined in @var{grob}.") { Grob *sc = unsmob_grob (grob); @@ -103,6 +126,18 @@ LY_DEFINE (ly_grob_object, "ly:grob-object", } +LY_DEFINE (ly_grob_set_object_x, "ly:grob-set-object!", + 3, 0, 0, (SCM grob, SCM sym, SCM val), + "Set @var{sym} in grob @var{grob} to value @var{val}.") +{ + Grob *sc = unsmob_grob (grob); + + LY_ASSERT_SMOB (Grob, grob, 1); + LY_ASSERT_TYPE (ly_is_symbol, sym, 2); + + sc->set_object (sym, val); + return SCM_UNSPECIFIED; +} /* TODO: make difference between scaled and unscalead variable in calling (i.e different funcs.) */ @@ -225,6 +260,22 @@ LY_DEFINE (ly_grob_parent, "ly:grob-parent", return par ? par->self_scm () : SCM_EOL; } +LY_DEFINE (ly_grob_set_parent_x, "ly:grob-set-parent!", + 3, 0, 0, (SCM grob, SCM axis, SCM parent_grob), + "Set @var{parent-grob} the parent of grob @var{grob} in axis @var{axis}.") +{ + Grob *gr = unsmob_grob (grob); + Grob *parent = unsmob_grob (parent_grob); + + LY_ASSERT_SMOB (Grob, grob, 1); + LY_ASSERT_TYPE (is_axis, axis, 2); + LY_ASSERT_SMOB (Grob, parent_grob, 3); + + Axis a = Axis (scm_to_int (axis)); + gr->set_parent (parent, a); + return SCM_UNSPECIFIED; +} + LY_DEFINE (ly_grob_properties, "ly:grob-properties", 1, 0, 0, (SCM grob), "Get the mutable properties of @var{grob}.") @@ -288,7 +339,7 @@ LY_DEFINE (ly_grob_suicide_x, "ly:grob-suicide!", LY_DEFINE (ly_grob_translate_axis_x, "ly:grob-translate-axis!", 3, 0, 0, (SCM grob, SCM d, SCM a), - "Translate @var{g} on axis@tie{}@var{a} over" + "Translate @var{grob} on axis@tie{}@var{a} over" " distance@tie{}@var{d}.") { Grob *me = unsmob_grob (grob); @@ -303,7 +354,7 @@ LY_DEFINE (ly_grob_translate_axis_x, "ly:grob-translate-axis!", LY_DEFINE (ly_grob_default_font, "ly:grob-default-font", 1, 0, 0, (SCM grob), - "Return the default font for grob @var{gr}.") + "Return the default font for grob @var{grob}.") { Grob *gr = unsmob_grob (grob); @@ -353,3 +404,20 @@ LY_DEFINE (ly_grob_common_refpoint_of_array, "ly:grob-common-refpoint-of-array", Grob *refp = common_refpoint_of_array (ga->array (), gr, Axis (scm_to_int (axis))); return refp ? refp->self_scm () : SCM_BOOL_F; } + +LY_DEFINE (ly_grob_chain_callback, "ly:grob-chain-callback", + 3, 0, 0, (SCM grob, SCM proc, SCM sym), + "Find the callback that is stored as property" + " @var{sym} of grob @var{grob} and chain @var{proc}" + " to the head of this, meaning that it is called" + " using @var{grob} and the previous callback's result.") +{ + Grob *gr = unsmob_grob (grob); + + LY_ASSERT_SMOB (Grob, grob, 1); + LY_ASSERT_TYPE (ly_is_procedure, proc, 2); + LY_ASSERT_TYPE (ly_is_symbol, sym, 3); + + chain_callback (gr, proc, sym); + return SCM_UNSPECIFIED; +}